如果我有一个包含将包含工具提示的可见性状态的静态变量的类,我将如何编写代码隐藏以在可见性变量更改时动态更改工具提示的可见性?
即当禁用工具提示选项时,不应该显示任何工具提示,但是当启用工具提示选项时,应该显示工具提示。(工具提示选项保存在不同类的静态变量中)工具提示及其连接的控件是动态创建的。
伪代码:
ToolTip myToolTip = new ToolTip();
Visiblity tooltipVis = Visibility.Visible;
Bind myToolTip.Visiblity to toolTipVis
//Any control with ToolTip should now show their respective ToolTip messages.
...
tooltipVis = Visibility.Hidden;
//Any control with ToolTip should now have ToolTip messages disabled
尝试绑定到 TreeViewItem:
TreeViewItem tvi = new TreeViewItem() { Header = tviHeader };
ToolTip x = new System.Windows.Controls.ToolTip();
x.Content = "This is text.";
Binding binder = new Binding {
Source = EnvironmentalVariables.ToolTipVisibility,
Path = new PropertyPath("Visibility")
};
x.SetBinding(VisibilityProperty, binder);
user.ToolTip = x;
public class EnvironmentalVariables {
public static Visibility ToolTipVisibility { get; set; }
}
这似乎没有将 Visiblity 绑定到 EnvironmentalVariables.ToolTipVisibility 变量。