簡體   English   中英

在運行時未應用按鈕樣式

[英]Button style not applied during runtime

因此,基本上,我有一個橫向三角形的按鈕(用於“播放”按鈕)。 在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如果使用字典,請確保已在App.xaml文件中聲明了它

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="file_name.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

然后,您可以使用DynamicResource來應用您的樣式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM