WPF控件库HandyControl中的Poptip是一个抽象对象,它不会出现在可视化树中,因此不能使用RelativeSource绑定。也不能使用ElementName,因为它找不到可控制的FrameworkContentElement。

通过使用Source和x:Reference可以实现这种绑定。x:Reference标记可以引用在xaml文件中其他位置声明的对象,这个对象需要通过x:Name命名来被引用。

必须将Poptip实例放在Resources中,例如Window.Resources,否则会因循环依赖而引发错误。

参考资料:How to hide wpf datagrid columns depending on a property

1、Resources定义示例

<Window.Resources>
    <hc:Poptip x:Key="MyPoptip" PlacementType="BottomLeft"
               Content="{Binding DataContext.SampleText, Source={x:Reference MyWindow}}"/>
</Window.Resources>

2、Poptip引用示例

<TextBox Grid.Column="0" x:Name="TextBox1" Text="{Binding SampleText}"
         FontSize="14" Margin="2,4,4,4" IsReadOnly="True">
    <hc:Poptip.Instance>
        <StaticResource ResourceKey="MyPoptip"/>
    </hc:Poptip.Instance>
</TextBox>

相关文章:

  • 2022-01-25
  • 2021-09-25
  • 2021-05-20
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2021-06-11
  • 2022-12-23
  • 2021-12-23
  • 2021-09-03
  • 2021-12-30
  • 2021-09-04
相关资源
相似解决方案