У меня есть стиль для ListBox и ListBoxItem
<Style TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{StaticResource DarkBackground}"/>
</Style>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="{StaticResource LightBackground}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Margin" Value="5,0,5,0"/>
<Setter Property="Padding" Value="5,0,5,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="{TemplateBinding Background}" Height="35"
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ItemsControl Focusable="False" Margin="{TemplateBinding Padding}" Foreground="{TemplateBinding Foreground}" VerticalContentAlignment="Center">
<ContentPresenter Tag="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"/>
</ItemsControl>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource GlassFX}"/>
<Setter Property="BorderBrush" Value="White"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Я добавляю новый ListBox в MainWindow:
<ListBox ItemsSource="{Binding AvailableClient}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem Tag="{Binding Path=ID}" Content="{Binding Path=Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Но моя привязка не работает ...
Если изменить стиль
<ContentPresenter Tag="{Binding Path=Tag.ID, RelativeSource={RelativeSource TemplatedParent}}" Content="{Binding Path=Content.Name, RelativeSource={RelativeSource TemplatedParent}}"/>
Все работают. Но мне нужен универсальный стиль для многих списков.
Как я могу это сделать?