2010-08-28 41 views
0

此XAML標記不起作用:如何綁定樣式中的數據?

<Label Content="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /> 

在此XAML代碼:

<Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}"> 
      <Style.Triggers> 
       <Trigger Property="Validation.HasError" Value="True"> 
        <Setter Property="Background" Value="Red"/> 
        <!--<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />--> 
        <Setter Property="ToolTip"> 
         <Setter.Value> 
          <StackPanel Orientation="Vertical"> 
           <Label Background="AliceBlue" Content="Input Error"/> 
           <Label Content="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /> 
          </StackPanel> 
         </Setter.Value> 
        </Setter> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 

我想通過(Validation.Errors )[0] .Error標籤中的TextBox的內容數據IDE工具提示財產

回答

0

Label使用RelativeSource Self將讓你的標籤作爲源,而你想要的TextBox。試試RelativeSource FindAncestor

<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TextBox}}, Path=(Validation.Errors)[0].ErrorContent}" /> 
相關問題