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