This is a first project using WPF and Styles. Development tool is VS2010.
I have the following style definitions:
<!-- Base Style Setting-->
<Style TargetType="{x:Type TabControl}" x:Key="TabControlBase">
<Setter Property="Height" Value="Auto" />
<Setter Property="Width" Value="Auto" />
</Style>
<Style TargetType="{x:Type TabItem}" x:Key="TabItemBase">
<Setter Property="Cursor" Value="Hand" />
</Style>
<!-- Sub Style Setting-->
<Style TargetType="{x:Type TabItem}" x:Key="LTabEquipment" BasedOn="{StaticResource TabItemBase}">
<Setter Property="Header">
<Setter.Value>
<StackPanel Orientation="Vertical">
<Image Height="36" Source="pack://application:,,,/Images/gears.png" Width="36" Margin="0,5,0,0" />
<TextBlock Text="Equipment" Margin="2,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Center" />
</StackPanel>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}" x:Key="LTabHistory" BasedOn="{StaticResource TabItemBase}">
<Setter Property="Header">
<Setter.Value>
<StackPanel Orientation="Vertical">
<Image Height="36" Source="pack://application:,,,/Images/history.png" Width="36" Margin="0,5,0,0" />
<TextBlock Text="History" Margin="2,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Center" />
</StackPanel>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}" x:Key="HTabDBase" BasedOn="{StaticResource TabItemBase}">
<Setter Property="Header">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Image Height="14" Source="pack://application:,,,/Images/dbase.png" Width="14" Margin="0,0,0,0" HorizontalAlignment="stretch" VerticalAlignment="stretch" />
<TextBlock Text="grid view" Margin="2,0,0,0" VerticalAlignment="center" HorizontalAlignment="center" />
</StackPanel>
</Setter.Value>
</Setter>
</Style>
Then in my MainWindow.xaml includes:
<TabControl Grid.Row="2" Name="tabLeft" TabStripPlacement="Left">
<TabItem x:Name="tabLeftEquipment" Style="{StaticResource LTabEquipment}">
<TabControl Style="{StaticResource TabControlBase}" Name="tabTopEquipment" >
<TabItem x:Name="tabTopEquipmentGridView" Style="{StaticResource HTabDBase}">
</TabItem>
</TabControl>
</TabItem>
<TabItem x:Name="tabLeftHistory" Style="{StaticResource LTabHistory}">
<TabControl Height="Auto" Name="tabTopHistory" Width="Auto">
<TabItem x:Name="tabTopHistoryGridView" Style="{StaticResource HTabDBase}" >
</TabItem>
</TabControl>
</TabItem>
At design time the styles provide the appearance I want, but at runtime I get an exception:
'Set property 'System.Windows.FrameworkElement.Style' threw an exception.'
Which points to line:
<TabItem x:Name="tabTopEquipmentGridView" Style="{StaticResource HTabDBase}">
Please help with finding the cause of the exception...Thanks!
I found the following in details, but still can't figure which element is causing the problem to correct.
Message=Specified element is already the logical child of another element. Disconnect it first.