I have a Toggle button defined in a style for a Silverlight TreeviewItem, and I would like it to start off in the IsChecked=true state. I tried simply setting IsChecked=True, but that has no effect.
Thanks
Example XAML:
<Style x:Name="CheckedToggleButton"
TargetType="ToggleButton">
<Setter Property="IsChecked"
Value="True" />
<Setter Property="Margin"
Value="0" />
</Style>
<Style x:Key="TreeViewItemStyle"
TargetType="controls:TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:TreeViewItem">
<Grid Margin="2">
<Grid.RowDefinitions>
<!--ContentPresenter Row-->
<RowDefinition Height="Auto" />
<!--ExpanderButton Row-->
<RowDefinition Height="Auto" />
<!--ItemsPresenter Row-->
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentPresenter Cursor="{TemplateBinding Cursor}"
HorizontalAlignment="Stretch"
Margin="{TemplateBinding Padding}"
x:Name="content"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Grid.RowSpan="1"/>
<ToggleButton x:Name="ExpanderButton"
Style="{StaticResource CheckedToggleButton}"
IsChecked="True"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Width="15"
Height="15"
Grid.Row="1" />
<ItemsPresenter x:Name="ItemsHost"
Visibility="{Binding ElementName=ExpanderButton, Path=IsChecked, Converter={StaticResource boolviz}}"
Grid.Row="2"
HorizontalAlignment="Stretch" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>