按钮悬停时XAML Windows 8应用程序蓝色边框
发布时间:2020-12-14 02:05:10 所属栏目:Windows 来源:网络整理
导读:我似乎无法找到答案.基本上,我创建了包含图像的按钮.将鼠标悬停在按钮上时 – 当前会出现蓝色边框.我想在图像上创建自己的悬停状态,所以我不需要蓝色边框 – 这就是推出间距.有谁知道如何删除它? Button Style="{StaticResource EventButton}" Image Source
我似乎无法找到答案.基本上,我创建了包含图像的按钮.将鼠标悬停在按钮上时 – 当前会出现蓝色边框.我想在图像上创建自己的悬停状态,所以我不需要蓝色边框 – 这就是推出间距.有谁知道如何删除它?
<Button Style="{StaticResource EventButton}"> <Image Source="/Assets/EventIcons/Business/event-Fire.png" Stretch="Fill"/> </Button> 我的风格: <Style x:Key="RiskButton" TargetType="Button"> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Margin" Value="4,4,4"/> <Setter Property="Width" Value="120"/> <Setter Property="Height" Value="120"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Padding" Value="0"/> <Setter Property="BorderThickness" Value="0"/> </Style> 谢谢你的帮助! 解决方法
在Blend for visual studio下打开您的项目(我建议您之前应用visual studio 2012更新2),选择您的按钮并右键单击 – >编辑模板 – >编辑副本 – >创建一个新的本地资源.
在状态面板中,您将看到按钮的不同可能状态(正常,按下,指针,聚焦……),选择例如“PointerOver”并将背景画笔更改为透明(或仅删除它). PointerOver之前: <VisualState x:Name="PointerOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverBackgroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverForegroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> PointerOver之后: <VisualState x:Name="PointerOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Null}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverForegroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> 现在蓝色边框消失了.要将其应用于其他按钮,可以在App.xaml中加载的字典中移动此样式,并使用Style属性. 要测试的完整xaml示例: <Page x:Class="AppSandBox.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AppSandBox" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Page.Resources> <Style x:Key="RiskButton" TargetType="Button"> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Margin" Value="4,4"/> <Setter Property="Width" Value="120"/> <Setter Property="Height" Value="120"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Padding" Value="0"/> <Setter Property="BorderThickness" Value="0"/> </Style> <ControlTemplate x:Key="ButtonControlTemplate1" TargetType="Button"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="PointerOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Null}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverForegroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedBackgroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedForegroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledBackgroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="BorderBrush"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledBorderThemeBrush}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonDisabledForegroundThemeBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused"> <Storyboard> <DoubleAnimation Storyboard.TargetName="FocusVisualWhite" Storyboard.TargetProperty="Opacity" To="1" Duration="0" /> <DoubleAnimation Storyboard.TargetName="FocusVisualBlack" Storyboard.TargetProperty="Opacity" To="1" Duration="0" /> </Storyboard> </VisualState> <VisualState x:Name="Unfocused" /> <VisualState x:Name="PointerFocused" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="3"> <ContentPresenter x:Name="ContentPresenter" Content="{TemplateBinding Content}" ContentTransitions="{TemplateBinding ContentTransitions}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Border> <Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="1.5" /> <Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="0.5" /> </Grid> </ControlTemplate> </Page.Resources> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Button Style="{StaticResource RiskButton}" VerticalAlignment="Top" Template="{StaticResource ButtonControlTemplate1}"> <Image Source="/Assets/Metro-icon.png" Stretch="Fill" Margin="10"/> </Button> </Grid> </Page> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net – 将控制台应用程序转换为服务?
- 使用wmctrl关闭窗口
- windows – 如何在每个批处理脚本运行后清除变量?
- windows – inno setup需要有关开始菜单下图标组的帮助
- 缓存 – 如何在Windows Phone 8上清除Cordova Web View的缓
- Windows尝试在提供的之前访问IPC $共享
- 如何将受管.NET程序集从内存中保存为EXE / DLL文件
- typescript – Element隐式具有’any’类型,因为类型’Wind
- windows-server-2003 – 为什么Server 2003没有系统还原?
- 适用于Windows的Phantomjs安装
推荐文章
站长推荐
热点阅读