今天在开发中遇到这样一个问题,先看下面的样式: <Style x:Key="MyButton" TargetType="{x:Type Button}"> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="Width" Value="96" /> <Setter Property="Height" Value="96...
<Style TargetType="Button"BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="FocusVisualStyle"Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/> </Style> 那么,有没有办法能够一次定义整个应用程序生效呢? 答案是—— wpf - Change the FocusVisualStyle in the entire ap...
</Setter> </Style> 运行一看,结果完全没有效果…… StackOverflow 上也有人说了这件事:xaml - How to redefine FocusVisualStyle for a WPF user control - Stack Overflow。Rohit Vats说需要通过单独为Button设置才能生效并在回答中贴出了代码。 然而同样的代码应用到项目中,我们会发现,我们此前定义的无 Key ...
<Style x:Key="{x:Static SystemParameters.FocusVisualStyleKey}"><Setter Property="Control.Template"><Setter.Value><ControlTemplate><Rectangle Margin="-3"StrokeThickness="3"Stroke="Gray"SnapsToDevicePixels="true"/></ControlTemplate></Setter.Value></Setter></Style><Style TargetType="Button"BasedOn="{...
</Button> 1. 2. 3. 4. 5. 6. 7. 变色的Button 样式: <Style x:Key="ButtonFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="3" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness...
以下XAML 會建立由兩個Button物件組成的使用者介面,並將GotFocus和LostFocus事件的事件處理常式附加到Button物件。 XAML <StackPanel><StackPanel.Resources><StyleTargetType="{x:Type Button}"><SetterProperty="Height"Value="20"/><SetterProperty="Width"Value="250"/><SetterProperty="HorizontalAli...
Style></Page.Resources><StackPanelBackground="Ivory"Orientation="Horizontal"><CanvasWidth="10"/><ButtonWidth="100"Height="30"FocusVisualStyle="{DynamicResource MyFocusVisual}">Focus Here</Button><CanvasWidth="100"/><ButtonWidth="100"Height="30"FocusVisualStyle="{DynamicResource MyFocusVisual}">Focu...
<Button Margin="122.275,127.2,139.525,126.2"FocusVisualStyle="{DynamicResource newFocusStyle}"/> <Button Margin="97.919,209.328,106.481,32.872"FocusVisualStyle="{x:Null}"/> </Grid> </Window> 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
<StyleTargetType="{x:TypeButton}"BasedOn="{x:Null}"> <SetterProperty="FocusVisualStyle"Value="{DynamicResourceNuclearButtonFocusVisual}"/> <SetterProperty="Background"Value="{DynamicResourceNormalBrush}"/> <SetterProperty="Foreground"Value="{DynamicResourceTextBrush}"/> <SetterProperty="BorderBrush"...
要删除默认MouseOver行为,Button您需要修改ControlTemplate。将您的Style定义更改为以下内容应该可以解决问题...