2
我在Silverlight用户控件中有一个按钮和图像。
当我点击按钮添加到它的边框。
当按下按钮时,我可以从按钮上移除边框吗?
谢谢。如何从silverlight中的点击按钮中删除边框?
我在Silverlight用户控件中有一个按钮和图像。
当我点击按钮添加到它的边框。
当按下按钮时,我可以从按钮上移除边框吗?
谢谢。如何从silverlight中的点击按钮中删除边框?
你将需要调整Button模板来做到这一点。首先获取现有模板(在Blend中使用Edit Copy of Template),如果您只有Visual Studio,可以从文档中获得该模板。 Button Styles and Templates。
复制整个风格和地方放置在一个资源在你的用户控件或更好,但在它自己的资源字典文件,包含在用户控件资源利用MergedDictionaries
: -
NoFocusRectangleButtonStyle.xaml: -
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="NoFocusRectangleButtonStyle" TargetType="Button">
<!-- copy of style contents from documentation -->
</Style>
</ResourceDictionary>
在你的用户控件: -
<UserControl .... >
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="NoFocusRectangleButtonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- other local resources -->
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" ...>
<Button Style="{StaticResource NoFocusRectangleButtonStyle}">
<Image Source="yourimage.png" />
</Button>
</Grid>
</UserControl>
现在你只需要调整Template
在复制样式中删除焦点Rectangle
。 您会在模板的底部找到它,并将其删除。然后再看看VisualStateGroups
这一套的结尾,你会看到一个名为“Focus”的VisualState
,删除它包含的Storyboard
,你就完成了。
很好的解决方案,谢谢。 – 2010-03-12 08:18:34