WPF に次のボタンとスタイルがあり、DataTrigger セクションでバインディングを一般化する必要があります。同じウィンドウに 10 個近くの同様のボタンがあり、各ボタンを異なるプロパティ (SelectedPositions、SelectedAgencies、.... )。実装することは可能ですか?
<Button x:Name="btnPosition"
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Command="{Binding PositionFilterCommand}"
Content="{l:Translate position}"
Style="{StaticResource NewButtonStyle}" />
<Style x:Key="NewButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="22" />
<Setter Property="Width" Value="Auto" />
<Setter Property="FontFamily" Value="OpenSans" />
<Setter Property="FontSize" Value="13" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Margin" Value="10,2,10,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="3">
<Grid x:Name="gridButton" Background="#54728e">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="img"
Grid.Column="0"
Width="24"
Height="24"
Source="Img/tick-white.png"
Visibility="Visible" />
<Rectangle x:Name="rect"
Grid.Column="1"
Fill="#54728e"
RadiusX="3"
RadiusY="3" />
<ContentPresenter Grid.Column="1"
Margin="5,0,5,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding SelectedPositions}" Value="{x:Static sys:String.Empty}">
<Setter TargetName="rect" Property="Fill" Value="#8bbcdf" />
<Setter TargetName="img" Property="Visibility" Value="Collapsed" />
<Setter TargetName="gridButton" Property="Background" Value="#8bbcdf" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>