How to make the first(primary) selected item in listbox multiple mode different in style? #7987
-
Like this, I selected "CCC" first, then "AAA" and "DDD", and i want "CCC" is Bold style I've actually done this by adding a I've also tried |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I did a different approach and it worked fine, I added a <TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Value="{StaticResource True}">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource ValueEqualsMultiConverter}">
<Binding Path="." />
<Binding Path="DataContext.PrimarySelectedItem"
RelativeSource="{RelativeSource AncestorType={x:Type ListBox}}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style> public class ValueEqualsMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
try
{
return values.All(x => x == values[0]);
}
catch
{
return Binding.DoNothing;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
Beta Was this translation helpful? Give feedback.
I did a different approach and it worked fine, I added a
PrimarySelectedItem
(implINotifyPropertyChange
) to the VM: