User Tools

Site Tools





How to set input key (enter for example) inside a container ?

<StackPanel Background="Transparent">
    <KeyBinding Command="{Binding ChangeColorCommand}"
                CommandParameter="{Binding ElementName=colorPicker, Path=SelectedItem}"
                Key="{Binding ChangeColorCommand.GestureKey}"
                Modifiers="{Binding ChangeColorCommand.GestureModifier}"/>
  <ListBox Name="colorPicker"

Sources :


How to set image in a column datagrid ?

<DataGrid ItemsSource="{Binding Customers}" AutoGenerateColumns="False" >
        <DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True">
                    <Image Source="{Binding Image}" />

How to set specific binding to a column DataGridTemplateColumn ?

I don't find any solution.

Explanation :

Sources :

How to have a textblock that adapt this size to a column ?

<DataGridTemplateColumn Header="Personne">
            <TextBlock DataContext="{Binding Personne}" HorizontalAlignment="Left" />


How to pass Converter param that is another type of String ?

<Button Grid.Column="8" Grid.Row="2" Content="Rechercher"
                            Style="{StaticResource SearchButton}">
        <Binding Path="IsBusy"
                 Converter="{StaticResource EqualsConverter}">

Sources : How to use a ConverterParameter which is not a string in XAML? (by Matthieu MEZIL)

How to get the parent of a control ?

{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=Name, Mode=TwoWay}

How to bind on the property Validation.HasError with a DataTrigger ?

  <DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource AncestorType={x:Type c:DatePicker}}" Value="false">
      <Setter Property="Visibility" Value="Collapsed" />

Sources :


How to wrap a text block too long using … ?

Use the property TextTrimming.

How to make TextBlock field selectable ?

You have to use a TextBox with the following style. Be careful with the Binding, you can only use the OneWay

<Style x:Key="TextBlockSelectable" TargetType="TextBox">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="IsReadOnly" Value="True" />
    <Setter Property="TextWrapping" Value="Wrap" />
technical_notes/public/20131018-wpf-faq.txt · Last modified: 2013/11/07 14:20 by Fabien Arcellier