IsSelected WPF TabItem Property
I have the following code:
<TabItem Name="tabItemGeneral">
<TabItem.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="tabGeneralImg" Property="Source" Value="Image/tabGeneralActive.png"></Setter>
</Trigger>
</TabItem.Triggers>
<TabItem.Header>
<StackPanel Orientation="Horizontal" Margin="0,-3,0,0">
<Image Name="tabGeneralImg" Source="Images/tabGeneral.png" Width="11" Height="11"></Image>
<Label Name="tabGeneralLbl" Content="General"></Label>
</StackPanel>
</TabItem.Header>
<Grid>
<!-- ... -->
</Grid>
</TabItem>
but I am getting Error 1 The member "IsSelected" is invalid because it has no qualifying type name. C: \ MyNET \ bluetooth \ iLockWPF \ iLock \ iLock \ MainWindow.xaml 63 60 iLock
at compile time. Why?
+6
source to share
3 answers
As CodeNaked said, it cannot use property triggers directly on elements. You should use HeaderTemplate instead.
<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"/>
<Label Name="tabGeneralLbl"
Content="General"/>
</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>
+8
source to share
The TabItem.Triggers collection inherits from FrameworkElement and can only contain Eventtriggers . What you have is not valid.
Triggers, MultiTriggers, DataTriggers, and MultiDataTriggers can only be used in Style.Triggers , ControlTemplate.Triggers, or DataTemplate.Triggers .
+4
source to share