所以基本上我有一个侧边三角形的按钮(用于播放按钮)。在xaml设计编辑器中,按钮正确地显示为三角形。但是,当我运行该应用程序时,它显示为一个标准的平淡无奇的windows按钮。样式如下:
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<ed:RegularPolygon x:Name="PlayerPlay" Fill="#FF080808" InnerRadius="1" PointCount="3" RenderTransformOrigin="0.5,0.5" Stretch="Fill" Stroke="Black">
<ed:RegularPolygon.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="90.635"/>
<TranslateTransform/>
</TransformGroup>
</ed:RegularPolygon.RenderTransform>
</ed:RegularPolygon>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
按钮在这里:
<Button x:Name="PlayerPlay" Click="PlayerPlay_Click_1" Content="" Margin="63.54,4.752,59.686,6.682" Style="{DynamicResource ButtonStyle1}"/>
你知道怎么回事吗?
谢谢!
你在哪里创建的样式?在Windows资源,在字典等
如果你的样式在你的按钮所在的资源中,那么使用StaticResource如果你使用dictionary,确保你已经在App.xaml文件中声明了它
交货<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="file_name.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
然后你可以使用DynamicResource来应用你的样式。