I created wpf-window as a class library. How do I make a binding with the converter to the Visibility property of the window? When executed, a XamlParseException is thrown. I add styles and resource dictionaries to Window.Resources, not to Application.Resources, therefore I have a DynamicResource window style. And with the converter did not happen.

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Style="{DynamicResource MyWindow}" Visibility="{Binding MyModel.IsVisible, Converter={StaticResource boolToVisConverter}}"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="MyDictionary.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> <BooleanToVisibilityConverter x:Key="boolToVisConverter"/> </Window.Resources> <Window.DataContext> ... 
  • Specifically, in my case - came up. You just need to add Mode = "TwoWay". - egeo

1 answer 1

Problem in StaticResource : the resource must be defined to the point of use.

Try this:

 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Style="{DynamicResource MyWindow}"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="MyDictionary.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> <BooleanToVisibilityConverter x:Key="boolToVisConverter"/> </Window.Resources> <Window.Visibility> <Binding Path="MyModel.IsVisible" Converter="{StaticResource boolToVisConverter}"/> </Window.Visibility> <Window.DataContext> ...