If I have a class that holds a static variable that will contain the Visiblity status of a Tooltip, how would I write the code-behind to dynamically change the Tooltip visiblity when the visiblity variable changes?
i.e. When Tooltip option is disabled, no Tooltips should be shown, but when Tooltip option is enabled, Tooltips should show up. (Tooltip option is held in a static variable in a different class) The Tooltip and the control it is connecting onto are dynamically created.
Pseudocode:
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
Attempt at binding to 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; }
}
This doesn’t seem to bind the Visiblity to the EnvironmentalVariables.ToolTipVisibility variable.
You could use ToolTipService.IsEnabled Attached Property for this.
Because you can’t bind to a static property (in WPF Version 4.5 you can) I would use this workaround to access the property from everywhere