Wpf 更改IsSelected选项卡控件上的图像
我希望能够在选择tabItem时更改它的图像,但我现在很难理解其他人是如何实现样式、模板和触发器的使用的 到目前为止,我有:Wpf 更改IsSelected选项卡控件上的图像,wpf,xaml,tabitem,Wpf,Xaml,Tabitem,我希望能够在选择tabItem时更改它的图像,但我现在很难理解其他人是如何实现样式、模板和触发器的使用的 到目前为止,我有: <TabControl HorizontalAlignment="Left" Height="386" VerticalAlignment="Top" Width="600" TabStripPlacement="Left" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
<TabControl HorizontalAlignment="Left" Height="386" VerticalAlignment="Top" Width="600" TabStripPlacement="Left" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
<TabItem Header="TabItem" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="-2,-2,-1,-28" Width="40" Height="59" HorizontalAlignment="Center" VerticalAlignment="Center">
<TabItem.Background>
<ImageBrush ImageSource="myImageLocation" Stretch="Uniform"/>
</TabItem.Background>
<Grid/>
</TabItem>
<TabItem Header="TabItem" Margin="0,89,0,-89" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="51" HorizontalAlignment="Center" Width="43">
<TabItem.Background>
<ImageBrush ImageSource="myImageLocation" Stretch="Uniform"/>
</TabItem.Background>
<Grid/>
</TabItem>
我已将图像设置为选项卡项标题的背景。请看以下示例:
<TabControl>
<TabControl.Resources>
<DataTemplate x:Key="tabItemGeneralHeaderTemplate">
<StackPanel Orientation="Horizontal" Margin="0,-3,0,0">
<Image Name="tabGeneralImg" Source="Image/tabGeneralActive.png" Width="11" Height="11"></Image>
<Label Name="tabGeneralLbl" Content="General"></Label>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter TargetName="tabGeneralImg" Property="Source" Value="Images/tabGeneral.png"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</TabControl.Resources>
<TabItem Name="tabItemGeneral" HeaderTemplate="{StaticResource tabItemGeneralHeaderTemplate}">
<Grid>
...
</Grid>
</TabItem>
</TabControl>
...
只需将图像的source属性更改为文件系统中的某个路径,就可以了:)