【发布时间】:2016-04-03 15:59:15
【问题描述】:
我有一个带有数据模板的网格视图,其中包括一个切换按钮。 Gridview 中项目的数据模板中有一个网格,带有一个风格化的切换按钮。切换按钮的样式位于 Grid.Resources 中。它工作正常,但是当我将样式从 Grid.Resources 移动到 Page.Resources 或 App.xaml 时,样式中定义的按钮内的内容会从除了 gridview 中第一次出现的按钮之外的所有内容中消失。这是样式:
<Style TargetType="ToggleButton" x:Key="teststyle">
<Setter Property="Padding" Value="0"/>
<Setter Property="Content">
<Setter.Value>
<Path HorizontalAlignment="Center" Stroke="Black" StrokeThickness="1.25" VerticalAlignment="Center" Height="9" Width="9" Stretch="Uniform" Fill="Black" Data="M 0,0 -11.78,-11.779 0,-23.561 l 1.061,1.061 -9.97,9.971 21.064,0 0,1.5 -21.064,0 9.97,9.968 L 0,0 Z" RenderTransformOrigin="0.5,0.5" >
<Path.RenderTransform>
<CompositeTransform Rotation="-90"/>
</Path.RenderTransform>
</Path>
</Setter.Value>
</Setter>
</Style>
以下是该行为的截图:http://imgur.com/a/8iZaD 上图是样式位于 Grid.Resources 中时的原始图像,下图是样式移动时的图像。
【问题讨论】:
-
您是否将 ToggleButton Style 显式设置为此 StaticResource 键(在您的数据模板中)?
-
@igrali 这是我的 ToggleButton 声明在数据模板中的样子:
<ToggleButton HorizontalAlignment="Right" VerticalAlignment="Center" Style="{StaticResource teststyle}" IsChecked="{x:Bind Path=Liked, Converter={StaticResource downvoteconverter},Mode=OneWay}" IsThreeState="False" Command="{x:Bind downvotecommand}"/>
标签: xaml microsoft-metro winrt-xaml uwp