【问题标题】:How remove border from clicked button in silverlight?如何从silverlight中的单击按钮中删除边框?
【发布时间】:2010-03-06 01:28:05
【问题描述】:

我的 silverlight 用户控件中有一个按钮和图像。
当我单击按钮时,会添加一个边框。
我可以在按下按钮时从按钮上移除边框吗?
谢谢。

【问题讨论】:

    标签: silverlight silverlight-3.0


    【解决方案1】:

    您需要调整 Button 模板才能做到这一点。首先获取现有模板(在 Blend this 中使用 Edit Copy of Template),如果您只有 Visual Studio,则可以从文档中获取。 Button Styles and Templates.

    复制整个样式并将其放在 UserControl 的某个资源中,或者更好的是放在它自己的 ResourceDictionary 文件中,并使用 MergedDictionaries 包含在 UserControl 资源中:-

    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就完成了。

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 1970-01-01
      • 2012-07-14
      • 2017-10-12
      • 1970-01-01
      • 2014-08-05
      • 2019-05-16
      • 2016-06-27
      • 2018-10-02
      相关资源
      最近更新 更多