pjdupreez
pjdupreez

Reputation: 717

DataTrigger on a Property of a Binding

I have label on a usercontrol with a property which has a binding. The string format property of this binding needs to be set depending on the data type of the underlying data that is bound to the property of the label's content. So if the property is bound to a date property in my viewmodel, I'd like to specify the string format in a datatrigger. Here is what I have tried but the StringFormat is not being recognised. Am I missing something or am I doing it wrong? Any advise would be greatly appreciated.

<Label
    x:Name="myLabel"
    Content="{Binding Path=myProperty}">
<Label.Style>
  <Style>
    <Style.Triggers>
      <DataTrigger
            Binding="{Binding ElementName=myLabel, Path=Content.Binding}"
            Value="{x:Type sys:DateTime}">
                  <Setter
                     Property="StringFormat"
                     Value="dd/MM/yyyy" />
     </DataTrigger>
   </Style.Triggers>
  </Style>
</Label.Style>

Upvotes: 2

Views: 169

Answers (1)

blindmeis
blindmeis

Reputation: 22435

why not simply use a converter?

 <Label Content="{Binding Path=myProperty, Converter={StaticResource MyContentConverter}}">

Upvotes: 2

Related Questions