Windows phone 7 WP7.1中未呈现自定义控件
我想在WP7.1中创建水印文本框,我遵循了链接 但该自定义控件不会在主页中呈现。我做错了什么 WaterMarkTextBox.csWindows phone 7 WP7.1中未呈现自定义控件,windows-phone-7,Windows Phone 7,我想在WP7.1中创建水印文本框,我遵循了链接 但该自定义控件不会在主页中呈现。我做错了什么 WaterMarkTextBox.cs public class WaterMarkTextBox : TextBox { public WaterMarkTextBox() { DefaultStyleKey = typeof(WaterMarkTextBox); } } WaterMarkTextBoxSty
public class WaterMarkTextBox : TextBox
{
public WaterMarkTextBox()
{
DefaultStyleKey = typeof(WaterMarkTextBox);
}
}
WaterMarkTextBoxStyle.xaml
<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:MyCustomControls">
<Style TargetType="local:WaterMarkTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:WaterMarkTextBox">
<Grid>
<Border>
<ContentControl x:Name="ContentTextBox" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
样本:
包括以下内容
xmlns:local=“clr命名空间:MyCustomControls;assembly=MyCustomControls”
解决方案:我添加了边界笔刷、边界厚度和背景色。现在工作正常。
<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:customcontrols">
<Style TargetType="local:WaterTextBox">
<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:WaterTextBox">
<Grid Background="Transparent">
<Border x:Name="EnabledBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}">
<ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
多谢各位