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 get Error 1 'IsSelected' member is not valid because it does not have a qualifying type name. C:\MyNET\bluetooth\iLockWPF\iLock\iLock\MainWindow.xaml 63 60 iLock
during compilation. Why?
As CodeNaked said, it is unable to 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>
The TabItem.Triggers collection is inherited from FrameworkElement and can only contain EventTriggers. What you have is not valid.
Triggers, MultiTriggers, DataTriggers, and MultiDataTriggers can only be used in the Style.Triggers, ControlTemplate.Triggers, or DataTemplate.Triggers collections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With