C# 单击按钮会产生意外效果
伙计们,我对WPF很陌生,我从山姆的电子书开始学习WPF。我只是尝试了书中给出的代码,如下所示C# 单击按钮会产生意外效果,c#,wpf,silverlight,xaml,wpf-controls,C#,Wpf,Silverlight,Xaml,Wpf Controls,伙计们,我对WPF很陌生,我从山姆的电子书开始学习WPF。我只是尝试了书中给出的代码,如下所示 <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="35
<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>
遗憾的是,当我单击按钮时,它开始缓慢闪烁,给出指定的黑色背景和白色/蓝色背景,并且它从不停止。我不知道为什么默认行为是这样的,因为我没有提到任何效果/样式/触发器/动画(是否有人可以指导我并纠正它。请让我也了解其背后的原因:(
自定义样式禁用系统动画。来自的代码能否给出一个代码示例,说明您正在尝试执行的操作。Steve,非常抱歉,我在上面也编写了此代码,duno为什么会出现此力:(这似乎是系统默认的动画。您可以通过编写自己的样式来禁用它,而不使用此动画。我刚刚使用您的xaml尝试过它,我看到了相同的情况。由于mouseover/mousedown事件,它会继续闪烁,并一直持续到它松开焦点为止。Hey Dantix,很好,我很感激,我尝试过此代码,非常棒。)rb,谢谢:)但我从没想过微软会在默认情况下做出这样一种非故意的行为。我看不出有什么好的理由让微软使用这种效果default@Divine动画的目的是让用户可以看到他们最后点击的按钮。他们过去会做那个笨拙的边框操作,现在他们会做动画高亮显示。只是UI中的另一个变化。@Divine No pr问题。当你的页面上只有一个按钮时,这是可以理解的。起初我也不知道发生了什么:P@steveg89::)是的,当我尝试第一个例子时,我感到震惊,因为我是新手:)为你干杯,伙计:)谢谢你……:)
<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>