I have implemented some listbox which contains border and a grid in this border.
<Style x:Key="SelectedHiglightStyle"
TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource MaterialDesignListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Transparent" />
</Style.Resources>
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="#316308" />
<Setter Property="Opacity"
Value="0.8" />
</Trigger>
</Style.Triggers>
</Style>
<ListBox IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="3"
ScrollViewer.CanContentScroll="False"
Style="{StaticResource MaterialDesignListBox}"
ItemsSource="{Binding Devices}"
SelectedItem="{Binding SelectedDevice, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
ItemContainerStyle="{StaticResource SelectedHiglightStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Rectangle Width="35"
Height="35"
Margin="5"
HorizontalAlignment="Left"
OpacityMask="{DynamicResource DashboardDeviceLogo}">
<Rectangle.Fill>
................
<Grid Grid.Column="1">
<StackPanel>
<TextBlock Text="{lex:Loc DeviceName}"
Margin="0,4,0,2" />
<TextBlock x:Name="tbDeviceName"
Text="{Binding Device.Name}"
FontSize="10" />
................
How I can change color of selected item border? Each item has his own view-model. Is there a easier way than broadcast message via Messanger (I'm using MVVM Light) , capture it in all DeviceViewModel's
, compare id of device and then bind the color from view-model?