Wednesday, October 16, 2013

WPF Converter in Resource Dictionary

Using converter is daily, in as general we doing that like this:

1. Define a c# ValueConverter

2. Set Xaml namespace like this :


3. set local resources with key like this:

   <converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" />         

4. just using the key inside your document where is needed:

< MediaElement Visibility="{Binding Path=X.Visibility, Converter={StaticResource boolToVisibilityCollapsedConverter}}"  />
But, inside Resource dictionary file when you need some Converter you cannot use local resource as Static Resources, so what you need is either Global static Converters allocate in your App.Xaml , or simply using the next xaml syntax:

1. add Xaml namespace like this :


2. and use Binding Converter syntax ..

<Setter Property="FontWeight">
    <Binding Path="(XValue)">
        <localConverters:BoolToBoldConverter />

QR: Inline images 1