【发布时间】:2011-03-19 20:53:57
【问题描述】:
我正在尝试为我的 WP7 应用程序构建自定义文本框控件。基本上我希望它有一个 GotFocus 功能,我希望能够让它有一个数字 InputScope
我使用以下资源作为尝试创建文本框自定义控件的基础:
- 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 如下:
<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>
【问题讨论】:
标签: windows-phone-7