2012-03-21 6 views
0

でレンダリングされていないしかし、そのカスタムコントロールはメインページにレンダリングされていません。私は何を間違えたの?カスタムコントロールは、私がリンク</p> <p><a href="http://www.windowsphonegeek.com/articles/WP7-WatermarkedTextBox-custom-control" rel="nofollow">http://www.windowsphonegeek.com/articles/WP7-WatermarkedTextBox-custom-control</a></p> <p>を追った私はWP7.1でWatermarkTextBoxを作成したいWP7.1

WaterMarkTextBox.cs

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> 

サンプル:ローカル= "CLR名前空間:

は、以下

のxmlns含まMyCustomControlsと、アセンブリ= MyCustomControls "

答えて

0

ソリューション:私はBorderBrush、BorderThicknessや背景色を追加しました。今すぐうまく動作します。

<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> 

ありがとうございます。

関連する問題

 関連する問題