2016-07-22 10 views
-1

私は以下のスタイルを持っています。WPFスタイルはStyle.Resourcesプロパティをオーバーライドします

<TextBox HorizontalContentAlignment="Center" Text="{Binding IpAddress, Mode=TwoWay}" ToolTip="Ip Address of camera"> 
        <TextBox.Style> 
         <Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib"> 
          <Style.Resources> 
           <VisualBrush x:Key="CueBannerBrush" AlignmentX="Center" AlignmentY="Center" Stretch="None"> 
            <VisualBrush.Visual> 
             <Label Content="Camera Ip Address" Foreground="Gray" Opacity="0.5" FontStyle="Italic" /> 
            </VisualBrush.Visual> 
           </VisualBrush> 
          </Style.Resources> 
          <Style.Triggers> 
           <Trigger Property="Text" Value="{x:Static sys:String.Empty}"> 
            <Setter Property="Background" Value="{StaticResource CueBannerBrush}" /> 
           </Trigger> 
           <Trigger Property="Text" Value="{x:Null}"> 
            <Setter Property="Background" Value="{StaticResource CueBannerBrush}" /> 
           </Trigger> 
           <Trigger Property="IsKeyboardFocused" Value="True"> 
            <Setter Property="Background" Value="White" /> 
           </Trigger> 
          </Style.Triggers> 
         </Style> 
        </TextBox.Style> 
       </TextBox>  

と答えhereで説明したように、私は再利用するSkin.xamlファイル内のリソースの辞書として、それを保管していました。

しかし、スタイルを適用するテキストボックスごとに、Content="Camera Ip Address"(スタイルの7行目)を異なるようにします。私は、SO答え:thisthisを見ました。これらのSOの回答はBasedOn属性を示唆していますが、私はこれを私のケースにどのように適用するかはわかりません。私の場合は、多くのレベルの深いようです。誰かが私にこれを達成する方法を提案してもらえますか?

基本的に私が欲しいものは、私は別のテキストボックスのために、私は、このコンテンツはカメラのログインになりたいながらコンテンツは、カメラのIPアドレスする必要があります適用1つのテキストボックスのために、です。これをどのように達成するのですか?

答えて

0

内部ラベルの内容をTextBoxのTagプロパティに設定してからLabelに表示することができます。

ようなので:

<TextBox Tag="Whatever you want"> 
    <TextBox.Style> 
     <Style TargetType="TextBox"> 
      <Style.Resources> 
       <VisualBrush x:Key="CueBannerBrush"> 
        <VisualBrush.Visual> 
         <Label Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TextBox},Path=Tag,Mode=OneWay" /> 
        </VisualBrush.Visual> 
       </VisualBrush> 
      </Style.Resources> 
     </Style> 
    </TextBox.Style> 
</TextBox> 
+0

私のスタイルは、トリガーを持っており、彼らが発射されていません。 :( – VivekDev

関連する問題