First, you create your property in Visual Studio by going to the Project Properties/Settings and creating an Application-scope bool ShowMyStackPanel
. This will automatically (1) create a Settings
class in the Properties
namespace and (2) add the following to your app.config:
<configuration>
...
<applicationSettings>
<CsWpfApplication1.Properties.Settings>
<setting name="ShowMyStackPanel" serializeAs="String">
<value>False</value>
</setting>
</CsWpfApplication1.Properties.Settings>
</applicationSettings>
</configuration>
In your WPF window, you can now simply bind to Properties.Settings.Default.ShowMyStackPanel
using a BooleanToVisibilityConverter
:
<Window ...
xmlns:prop="clr-namespace:CsWpfApplication1.Properties"
...>
<Window.Resources>
<BooleanToVisibilityConverter x:Key="MyBoolToVisibilityConverter" />
</Window.Resources>
...
<StackPanel Visibility="{Binding Source={x:Static prop:Settings.Default},
Path=ShowMyStackPanel,
Converter={StaticResource MyBoolToVisibilityConverter}}">
...
</StackPanel>
...
</Window>