User Tools

Site Tools



WPF - Xaml - Notes

Package Uri

To get resources, you can adress them through uri in wpf.

Sources :


Resource Dictionary helps to gather informations about presentation rules as css. To declare it in a separate file, you can do that :

            <ResourceDictionary Source="../Styles/DatePicker.xaml"/>

As you can see above, we use relative path. Sometimes, it's better to do the reference using the path relative to components.

<!-- Refer to embedded resources -->
<ResourceDictionary Source="ResourceDll;component/Styles/DatePicker.xaml" />

Sources :

Attached Properties

Attached properties follows precedence rules when you affect them 1)

Sources :

Markup Extension



Sources :

Visual states

In WPF, we can refer visual states to controls or even windows. To complete this approach we can define visual transition.

Visual states come from silverlight that does not support trigger.

<UserControl x:Class="MainView"
      <VisualStateGroup x:Name="MainVisualStateGroup">
        <VisualState x:Name="Error"/>
        <VisualState x:Name="InvalidUnfocused"/>

Sources :


  • AdornedElementPlaceholder

Sources :


Each binding typically has these four components:

  • a binding target object
  • a target property
  • a binding source
  • a path to the value in the binding source to use.

How to do multibinding for a converter ?

		<MultiBinding Converter="{StaticResource HasAutorizationConverter}" ConverterParameter="ETA">
				<Binding Path="Context1" />
				<Binding Path="Context2" />



Triggers define a list of setters that are executed if the specified condition is fulfilled. WPF knows three diferent types of triggers.

Setting trigger

To set style trigger directly in component, use this code :

	<Style TargetType="wpf:ChildWindow">
			<DataTrigger Binding="{Binding Path=Type}" Value="{x:Static type:Type.ERREUR}">
				<Setter Property="Background" Value="Yellow" />

Property trigger

<Style x:Key="styleWithTrigger" TargetType="Rectangle">
    <Setter Property="Fill" Value="LightGreen" />
       <Trigger Property="IsEnabled" Value="false">
          <Setter Property="Background" Value="#EEEEEE" />
<Rectangle Style="{StaticResource styleWithTrigger}"></Rectangle>


      <Condition Property="HasItems" Value="false" />
      <Condition Property="Width" Value="Auto" />
    <Setter Property="MinWidth" Value="120"/>

Sources :

technical_notes/public/wpf-xaml.txt · Last modified: 2014/01/03 17:01 by Fabien Arcellier