- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题以前曾被问过,但在大多数情况下不超过 2 年前,并且通常特定于 WPF。答案可能仍然相同,但它就在这里。我正在尝试构建一个三角形(箭头)按钮,当鼠标悬停在其上方时,该按钮会改变颜色并增大大小。我已经为一个按钮工作了。但是现在我需要带有指向不同方向的箭头的按钮。我想尽可能多地重用代码。如果不使用自定义按钮控件,我想不出完全使用相同样式的方法,因此我试图通过将鼠标悬停动画作为资源来重用它。当我在按钮模板的 VisualStateManager 中将 Storyboard 引用为 StaticResource 时,它会使我的按钮完全消失。为什么这不起作用?
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:System="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d"
x:Class="SilverlightTest.MainPage"
Width="640" Height="480">
<UserControl.Resources>
<Storyboard x:Key="ArrowMouseOver">
<DoubleAnimation Duration="0:0:0.165" To="1.25" Storyboard.TargetProperty="(UiElement.RenderTransform).(ScaleTransform.ScaleX)" Storyboard.TargetName="polygon"/>
<DoubleAnimation Duration="0:0:0.165" To="1.25" Storyboard.TargetProperty="(UiElement.RenderTransform).(ScaleTransform.ScaleY)" Storyboard.TargetName="polygon"/>
<ColorAnimation Duration="0:0:0.165" To="#FF9BD6FF" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF70ACDF" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF7DAEFF" Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF2B5CB4" Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
</Storyboard>
<Style x:Key="LeftArrow" TargetType="Button">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grdRoot" RenderTransformOrigin="0.5,0.5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.165"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver" Storyboard="{StaticResource ArrowMouseOver}">
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Polygon x:Name="polygon" Grid.Row="0" Margin="1" StrokeThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Polygon.Points>
<Point X="10"/>
<Point X="0" Y="5" />
<Point Y="10" X="10" />
</Polygon.Points>
<Polygon.RenderTransform>
<ScaleTransform />
</Polygon.RenderTransform>
<Polygon.Fill>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FFA9A9A9"/>
<GradientStop Color="#FFD3D3D3" Offset="1"/>
</LinearGradientBrush>
</Polygon.Fill>
<Polygon.Stroke>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FF696969"/>
<GradientStop Color="#FF939393" Offset="1"/>
</LinearGradientBrush>
</Polygon.Stroke>
</Polygon>
<ContentPresenter Grid.Row="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Button Style="{StaticResource LeftArrow}" HorizontalAlignment="Left" VerticalAlignment="Top">
</Button>
</Grid>
最佳答案
听起来您应该介绍自己的 Button
类(class)。
我会这样做:
<my:GlowingArrowButton ArrowDirection="Left"/>
<Style TargetType="my:GlowingArrowButton">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="my:GlowingArrowButton">
<Grid x:Name="grdRoot" RenderTransformOrigin="0.5,0.5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.165"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"
<Storyboard>
<DoubleAnimation Duration="0:0:0.165" To="1.25" Storyboard.TargetProperty="(UiElement.RenderTransform).(ScaleTransform.ScaleX)" Storyboard.TargetName="polygon"/>
<DoubleAnimation Duration="0:0:0.165" To="1.25" Storyboard.TargetProperty="(UiElement.RenderTransform).(ScaleTransform.ScaleY)" Storyboard.TargetName="polygon"/>
<ColorAnimation Duration="0:0:0.165" To="#FF9BD6FF" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF70ACDF" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF7DAEFF" Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
<ColorAnimation Duration="0:0:0.165" To="#FF2B5CB4" Storyboard.TargetProperty="(Shape.Stroke).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="polygon" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<LayoutTransformer
LayoutTransform="{Binding Path=ArrowDirection,
RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource RotationTranslator_ToBeImplemented}}"
Grid.Row="0"
HorizontalAlignment="Center">
<Polygon
x:Name="polygon"
Margin="1"
StrokeThickness="{TemplateBinding BorderThickness}"
RenderTransformOrigin="0.5,0.5">
<Polygon.Points>
<Point X="10"/>
<Point X="0" Y="5" />
<Point Y="10" X="10" />
</Polygon.Points>
<Polygon.RenderTransform>
<ScaleTransform />
</Polygon.RenderTransform>
<Polygon.Fill>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FFA9A9A9"/>
<GradientStop Color="#FFD3D3D3" Offset="1"/>
</LinearGradientBrush>
</Polygon.Fill>
<Polygon.Stroke>
<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
<GradientStop Color="#FF696969"/>
<GradientStop Color="#FF939393" Offset="1"/>
</LinearGradientBrush>
</Polygon.Stroke>
</Polygon>
</LayoutTransformer>
<ContentPresenter
Grid.Row="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class GlowingArrowButton : ButtonBase
{
public GlowingArrowButton()
{
DefaultStyleKey = typeof (GlowingArrowButton);
}
public ArrowDirection ArrowDirection
{
get { return (ArrowDirection) GetValue( ArrowDirectionProperty ); }
set { SetValue( ArrowDirectionProperty, value ); }
}
public static readonly DependencyProperty ArrowDirectionProperty =
DependencyProperty.Register( "ArrowDirection", typeof( ArrowDirection ), typeof( GlowingArrowButton ), new PropertyMetadata( default( ArrowDirection ) ) );
}
public enum ArrowDirection
{
Left,
Up,
Right,
Down
}
public class RotationTranslator : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var arrowDirection = (ArrowDirection) value;
switch (arrowDirection)
{
case ArrowDirection.Left: return new RotateTransform{ Angle = 0 };
case ArrowDirection.Up: return new RotateTransform { Angle = 90 };
case ArrowDirection.Right: return new RotateTransform { Angle = 180 };
case ArrowDirection.Down: return new RotateTransform { Angle = -90 };
}
throw new InvalidOperationException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotSupportedException();}
}
关于xaml - 如何在 Silverlight 5 中使用 VisualStateManager 重用 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10954024/
我正在尝试从 F# 编译代码以在 Silverlight 中使用。我编译: --noframework --cliroot "C:\program Files\Microsoft Silverligh
我正在为 Silverlight 安装一个编程环境并试图理顺需要安装的内容,感谢反馈: 在 http://silverlight.net/GetStarted ,第一点允许您安装“ Silverlig
Silverlight RIA 值得学习还是我应该坚持普通的 Silverlight? 背景: 我在 WPF 中做了几个小应用程序 我有 12 年的 VB6/WinForms 模型商业应用经验 我希望
我已经熟悉 Silverlight 编程,但没有任何 GIS 经验。 我作为 Silverlight 开发人员的角色只是显示现有的 GIS 数据。 如果你们有任何经验arcGIS silverligh
我需要在我的 Silverlight 应用程序中创建滚动选取框。选取框需要从右向左滚动。当它完成滚动时,它需要自动重新启动 诀窍是,我需要使用 ItemsControl,因为项目将在滚动时添加到列表中
Silverlight 导航模板在浏览器外运行时是否有效? 最佳答案 当然可以。 并且您可以使用 NavigationServices 函数来创建自定义的“后退”或“前进”按钮 很好的例子:Link
用户通过导航到给定的 URL 在他们的浏览器中启动 Silverlight 应用程序。 然后用户打开另一个浏览器并通过导航到相同的 URL 启动相同的 Silverlight 应用程序。 应用程序的第
Silverlight 4 程序集二进制文件是否与 Silverlight 5 兼容。SL4 程序集是否“在 SL5 运行时中运行”?如果兼容,是否100%兼容。您应该能够在您的 SL5 项目中使用第
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我正在寻找是否可以在可以在 application.resources 中设置然后在整个应用程序中使用的 Silverlight 控件中使用应用程序范围的字体。他们不需要指定有关字体的其他内容,例如粗
我正在使用Silverlight4。我想用一个可用字体列表填充组合框。我搜索过很多东西,找不到解决方法。似乎有很多死胡同。五月份曾提出过类似的问题,但没有合适的答案。 当然不是不可能吗? 最佳答案 如
我正在为 Silverlight 很好地实现弱事件模式以避免内存泄漏。 似乎有一些实现,但代码并非微不足道,很难知道哪个是正确的。我找不到微软的任何官方推荐。 如果可能的话,我追求简单的语法。 干杯。
Silverlight 应用程序是在您每次访问该站点时都会下载,还是会检查版本/大小信息并仅下载较新版本的文件? 最佳答案 Silverlight 2 在这方面没有什么特别的,我读过的最简洁的解释来自
我正在尝试在 silverlight 中使用样式触发器,如下所示:
我想尝试制作一个包含多个 Silverlight 画廊中的图片的 asp 网站。我想这样做的原因是我想要这样的东西: Text describing some places. Gallery with
WPF 3.5 有 PresentationTraceSources用于诊断和WPFPerf用于性能和数据绑定(bind)诊断。 Silverlight 是否有等效的工具/库? 最佳答案 尽管我已将
我有一个表示有向图的数据结构,我正在寻找一个好的 Silverlight 可视化,以允许我从一个节点导航到另一个节点,最好有一些漂亮的动画。 有没有人知道这种显示的任何好的 UI 控件或框架?甚至来自
我可以将byte []转换为图像: byte[] myByteArray = ...; // ByteArray to be converted MemoryStream ms = new Memo
我有多个Silverlight项目,希望使用相同的样式,配色方案和一些模板化对象。 我该如何完成? 最佳答案 一种实现方法是创建一个新的silverlight类库,该库将是您共享的主题/样式程序集,其
我正在尝试使用 SLLAUNCHER.EXE 启动已安装的 SL Out-of-Browser App。运行以下命令后,桌面上的 MyApp 启动图标就消失了。如果我在没有覆盖开关的情况下尝试它,则不
我是一名优秀的程序员,十分优秀!