I have the following xaml style in WPF, and I would like to开发者_高级运维 port it to silverlight. I am having trouble with the ControlTemplate Triggers that do not exist in silverlight. I was trying Interaction.Triggers but it is not working. How can I convert the ControlTemplate Triggers to something similar in silverlight?
<Style x:Key="ImageExpander" TargetType="Expander">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Expander">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Name="ContentRow" Height="0"/>
</Grid.RowDefinitions>
<Border Name="Border" Grid.Row="0">
<Border.Background>
<ImageBrush ImageSource="image.png" Stretch="Fill" />
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0" Margin="4" ContentSource="Header" RecognizesAccessKey="True"></ContentPresenter>
<ToggleButton Grid.Column="1" IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Template="{StaticResource ImageExpanderToggleButton}"/>
</Grid>
</Border>
<Border Name="Content" Grid.Row="1">
<ContentPresenter Margin="0" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Thanks in advance.
In general the concept of property triggers in WPF is usually replaced by visual states in Silverlight. In the case of the Expander.IsExpanded property, this corresponds to the Expanded visual state.
So in your template you'll need something like:
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ExpansionStates">
<VisualState x:Name="Collapsed"/>
<VisualState x:Name="Expanded">
<Storyboard>
... (some animation)
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
...
</Grid>
精彩评论