【问题标题】:How to change ToolTip binding programmatically?如何以编程方式更改 ToolTip 绑定?
【发布时间】:2011-07-30 13:04:47
【问题描述】:

我知道在 XAML 中您可以更改工具提示的绑定...

<TextBlock Text="ABC" ToolTip="{Binding Path=SomeProperty}" /> 

如何以编程方式为工具提示设置相同的绑定?

【问题讨论】:

    标签: wpf xaml binding


    【解决方案1】:

    XAML:

    <TextBlock Text="ABC" x:Name="_textBlock" />
    

    代码:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new Data{ Tip="Help!" };
    
            Binding binding = new Binding("Tip");
    
            _textBlock.SetBinding(TextBlock.ToolTipProperty, binding);
        }
    }
    

    注意:我无法使用 C# 代码突出显示代码,抱歉

    【讨论】:

      【解决方案2】:

      尝试新的绑定{Path="SomeProperty"}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-04
        • 1970-01-01
        • 2012-12-09
        • 1970-01-01
        • 1970-01-01
        • 2016-11-06
        • 2023-03-22
        相关资源
        最近更新 更多