WPF Datatrigger not firing when expected

Alternatively, you could replace your XAML with this: <TextBlock Margin=”0,0,5,0″ Text=”{Binding ElementName=EditListBox, Path=SelectedItems.Count}”/> <TextBlock> <TextBlock.Style> <Style TargetType=”{x:Type TextBlock}”> <Setter Property=”Text” Value=”items selected”/> <Style.Triggers> <DataTrigger Binding=”{Binding ElementName=EditListBox, Path=SelectedItems.Count}” Value=”1″> <Setter Property=”Text” Value=”item selected”/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> Converters can solve a lot of binding problems but having a lot of specialized converters gets very messy.

In WPF, how to debug triggers?

There is an excellent article on WPF Mentor by entitled How to debug triggers using Trigger-Tracing (cached version here). I’ve used it innumerable times to debug into triggers, it’s an amazing technique for anybody that uses WPF at a professional level. Unfortunately, the link to the source code is partially broken, so I am mirroring … Read more

WPF Trigger based on Object Type

This is based on @AndyG’s answer but is a bit safer because it’s strongly typed. Implement an IValueConverter named DataTypeConverter, which accepts an object and returns its Type (as a System.Type): public class DataTypeConverter:IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value?.GetType() ?? Binding.DoNothing; } public object ConvertBack(object value, … Read more

How to get DataTemplate.DataTrigger to check for greater than or less than?

You could create an IValueConverter, which converts an integer to a boolean based on the CutOff. Then use DataTrigger.Value of True (or False, depending on what you are returning). WPF DataTriggers are strictly equality comparers if I remember correctly. So something similar to: public class CutoffConverter : IValueConverter { public object Convert(object value, Type targetType, … Read more

DataTrigger where value is NOT null?

This is a bit of a cheat but I just set a default style and then overrode it using a DataTrigger if the value is null… <Style> <!– Highlight for Reviewed (Default) –> <Setter Property=”Control.Background” Value=”PaleGreen” /> <Style.Triggers> <!– Highlight for Not Reviewed –> <DataTrigger Binding=”{Binding Path=REVIEWEDBY}” Value=”{x:Null}”> <Setter Property=”Control.Background” Value=”LightIndianRed” /> </DataTrigger> </Style.Triggers> </Style>

How can I provide multiple conditions for data trigger in WPF?

Use MultiDataTrigger type <Style TargetType=”ListBoxItem”> <Style.Triggers> <DataTrigger Binding=”{Binding Path=State}” Value=”WA”> <Setter Property=”Foreground” Value=”Red” /> </DataTrigger> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding=”{Binding Path=Name}” Value=”Portland” /> <Condition Binding=”{Binding Path=State}” Value=”OR” /> </MultiDataTrigger.Conditions> <Setter Property=”Background” Value=”Cyan” /> </MultiDataTrigger> </Style.Triggers> </Style>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)