0

伙计们,我对 WPF 广告很陌生,从 Sam 的电子书开始学习它。我刚刚尝试了书中给出的相同代码,如下所示

<Window x:Class="wpfTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

    <Button Background="Black">
        <Button.Content>
            <Ellipse Width="103" Height="107" Fill="Yellow" />
        </Button.Content>
    </Button>
</Window>

遗憾的是,当我单击按钮时,它开始缓慢闪烁,给出指定的黑色背景以及白色/蓝色背景,并且它永远不会停止。我不知道为什么默认行为是这样的,因为我没有提到任何效果/样式/触发器/动画。:(有人可以指导我并纠正它。请让我也理解背后的原因:(

4

1 回答 1

0
<Window x:Class="testwpf.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <Style x:Key="BorderlessButton" TargetType="{x:Type Button}">
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Name="border" Background="{TemplateBinding Background}">
                        <ContentPresenter Name="content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                  Margin="{TemplateBinding Padding}"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <Button Style="{DynamicResource BorderlessButton}">
        <Button.Content>
            <Ellipse Width="103" Height="107" Fill="Yellow" />
        </Button.Content>
    </Button>
</Grid>

自定义样式禁用系统动画动画。来自这里的代码

于 2012-08-07T08:38:48.063 回答