簡體   English   中英

工具提示的樣式化文本塊綁定改為綁定到控件模板

[英]Styled textblock binding for tooltip is binding to control template instead

我正在嘗試將文本塊的工具提示綁定到文本塊文本所綁定的值。

以下適用於應用此樣式的文本塊:

<Style x:Key="GridCell" TargetType="{x:Type TextBlock}">
    <Setter Property="ToolTip" Value="{Binding Converter={StaticResource CellToolTipConverter}}"/>
</Style>

<DataTemplate x:Key="GridCellContentTemplate">
     <TextBlock Style="{StaticResource GridCell}"
                Text="{Binding Converter=..."/>
</DataTemplate>

<xcdg:Column FieldName="FXRate" CellContentTemplate="{GridCellContentTemplate}" />

工作提示

但是出於某些奇怪的原因,當我嘗試將此樣式作為資源傳遞給datagrid stat單元時,

<Style x:Key="{x:Type xcdg:StatCell}" TargetType="{x:Type xcdg:StatCell}">
    <Style.Resources>
        <Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">
             <Setter Property="ToolTip" Value="{Binding Converter={StaticResource CellToolTipConverter}}"/>
        </Style>
    </Style.Resources>
</Style>

<xcdg:StatCell FieldName="Limit">
      <TextBlock Text="{Binding Source={StaticResource Layers}, Path=StatLimit, Converter=..." />
</xcdg:StatCell>

工具提示破損

如您所見,工具提示已綁定到某些DataTemplate,而不是綁定到文本框文本的任何內容。 據我所知,這兩者沒有區別,實際上,后者似乎更為直接。

誰能弄清楚為什么第二個工具提示綁定無法像第一個那樣工作?


請注意,我可以確定綁定正在進入單元格中的文本框,因為如果將綁定更改為:

<Style x:Key="{x:Type xcdg:StatCell}" TargetType="{x:Type xcdg:StatCell}">
    <Style.Resources>
        <Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">
             <Setter Property="ToolTip" Value="{Binding Path=Text, RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource CellToolTipConverter}}"/>
        </Style>
    </Style.Resources>
</Style>

我得到這個:

嘗試

但是,當然,我不需要textblock文本屬性,我希望將textblock綁定到原始值。

這樣做的原因是文本綁定正在查看工具提示附加到的對象的數據上下文。 恰巧xcdg:StatCell出於其自身目的劫持了數據上下文,因此任何子可視元素都無法訪問綁定到的原始屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM