How remove border from clicked button in silverlight?

自古美人都是妖i 提交于 2019-12-10 23:38:09

问题


I have a button and image inside it in my silverlight user control.
When I click to the button a border added to it.
Can I remove border from button when it is pressed?
Thanks.


回答1:


You will need to tweak the Button template to do that. First get hold of the existing template (in Blend this where you use Edit Copy of Template) which you can get from the documentation if you only have Visual Studio. Button Styles and Templates.

Copy the entire style and place it in a resource somewhere in your UserControl or better yet in a ResourceDictionary file of its own and included in the UserControl resources using 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>

In your UserControl:-

<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>

Now you just need to tweak the Template in the copied style to remove the Focus Rectangle. You'll find it right at the bottom of the template, delete it. Then look further up to the end of the set of VisualStateGroups, you'll see a VisualState called "Focus", delete the Storyboard it contains and you are done.



来源:https://stackoverflow.com/questions/2387013/how-remove-border-from-clicked-button-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!