2
我想爲我的WP7應用程序構建一個自定義的文本框控件。基本上我希望它有一個的GotFocus功能,我希望能夠使它有一些InputScopewp7:自定義控件的功能
我使用以下資源作爲我的基地,試圖創建一個文本框自定義控制:
- http://www.windowsphonegeek.com/articles/WP7-WatermarkedTextBox-custom-control
- http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps
我可以得到文本框在我的應用程序中顯示,但我不能在GotFocus呼叫,而無需在應用程序中的功能(這違背了目的)工作。
我通常會調用的GotFocus函數也在genericTextbox的類中。我將如何調用GotFocus和InputScope?
的資源字典如下:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:local="clr-namespace:wp7CustomControlsLibrary">
<Style TargetType="local:genericTextbox">
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/>
<Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:genericTextbox">
<Grid Background="Transparent">
<Border x:Name="EnabledBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}">
<Grid>
<ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>