I have previously added a "close" button to a sip by setting InputScope to Search, handling the key up event and calling Focus if the Key is Enter.
I tried to do the same thing in a user control containing a textblock and a textbox and the sip just won't close.
Here is the user control:
XAML
<UserControl
x:Class="SlidePanels.UserControls.TextBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignWidth="480">
<StackPanel
Orientation="Vertical"
Background="{StaticResource PhoneChromeBrush}">
<TextBlock
x:Name="LabelControl"
Text="Label Control"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBox
x:Name="TextControl"
Text="Text Control"
InputScope="Search"
KeyUp="TextControl_KeyUp" />
</StackPanel>
Code:
using System.Windows.Input;
namespace SlidePanels.UserControls
{
public partial class TextBoxControl
{
public TextBoxControl()
{
InitializeComponent();
}
public string FieldName { get; set; }
public string Label
{
set { LabelControl.Text = value; }
}
public string Text
{
get { return TextControl.Text; }
set { TextControl.Text = value; }
}
private void TextControl_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Focus();
}
}
}
}
Any ideas what I'm doing wrong?