【问题标题】:How do I pass a value to the Text attribute of the TextBlock tag found in the ResourceDictionary from the TextBox tag如何从 TextBox 标记向 ResourceDictionary 中找到的 TextBlock 标记的 Text 属性传递一个值
【发布时间】:2021-07-07 18:37:51
【问题描述】:

enter image description here如何从 TextBox 标记向 ResourceDictionary 中找到的 TextBlock 标记的 Text 属性传递一个值? 我使用 Tag 属性将数据传递给 Path。 Data="{绑定标签,RelativeSource={RelativeSource AncestorType={x:Type TextBox}}}"

Page.xaml

<TextBox x:Name="SearchTextBox"
         VerticalAlignment="Center" 
         VerticalContentAlignment="Center"
         Tag="{StaticResource SearchIcon}"/>

ResourceDictionary.xaml

<Style TargetType="{x:Type TextBox}">
...
  <TextBlock x:Name="SearchTextBlock" 
             Grid.Column="1"
             Foreground="{TemplateBinding Foreground}"
             Text="???"
             VerticalAlignment="Center"/>
  <ScrollViewer Grid.Column="1" 
                VerticalContentAlignment="Center"
                x:Name="PART_ContentHost" />
...   
</Style>

【问题讨论】:

    标签: xaml


    【解决方案1】:

    我完全忘记了 ToolTip 属性。

    Text="{TemplateBinding ToolTip}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 2016-03-28
      • 2014-01-28
      • 1970-01-01
      • 2014-11-25
      • 2015-06-29
      • 2011-09-14
      相关资源
      最近更新 更多