如何将 WPF 中的 Expander 样式转换为 Silverlight
我在 WPF 中有以下 xaml 样式,我想将其移植到 silverlight。 我在使用 silverlight 中不存在的 ControlTemplate 触发器时遇到问题。 我正在尝试 Interaction.Triggers 但它不起作用。 如何将 ControlTemplate 触发器转换为 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>
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,WPF 中属性触发器的概念通常被 Silverlight 中的视觉状态所取代。对于 Expander.IsExpanded 属性,这对应于 Expanded 视觉状态。
因此,在您的模板中,您需要类似的内容:
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: