views:

31

answers:

2

Hi,

To make things simple I thought I could add some settings in my resources and bind it to whatever/whenever I need it. For example, I wanted to be able to toggle the visibility of some objects. So I made the following XAML:

// Namespaces....
xmlns:win="clr-namespace:System.Windows;assembly=System.Windows"
// Namespaces....
<UserControl.Resources>
    <win:Visibility x:Key="ReflectionVisibility" />
</UserControl.Resources>

Although, now I'm wondering how I can:

  • Set a default value in the XAML

  • Change the value in code behind

Thanks!

A: 

You can make a style with triggers to toggle visibility. Add that style in the resource. Bind the style to the control.

John
A: 

You're on the right track

<Visibility x:Key="ReflectionVisibility">Collapsed</Visibility>

Then in your control

Visibility="{StaticResource ReflectionVisibility}"
Stephan
Works, thanks!!
SaphuA