从 UserControl 的样式访问转换
我有一些用于 UserControl 的 XAML,大致如下所示:
<UserControl>
<UserControl.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</UserControl.RenderTransform>
<UserControl.Style>
<Style TargetType="UserControl">
<Style.Triggers>
<DataTrigger Binding="..." Value="...">
<Setter Property="RenderTransform.ScaleX" Value="0.5" />
<Setter Property="RenderTransform.ScaleY" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
</UserControl>
但是当我编译时,我收到错误:
无法解析样式属性“ScaleX”。验证是否拥有 type 是 Style 的 TargetType,或者使用 Class.Property 语法 指定属性。
我已经尝试了该属性的各种排列,但我找不到真正有效的一种。在其他情况下,我将仅命名 ScaleTransform 并使用 TargetName 引用它。但您不能在样式设置器中使用 TargetName。
我想我的选择是这样的:
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
</Setter.Value>
</Setter>
但这似乎有点严厉。
我确信我只是错过了一些东西。但我真的需要一些帮助。
I've got some XAML for a UserControl that looks roughly like this:
<UserControl>
<UserControl.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</UserControl.RenderTransform>
<UserControl.Style>
<Style TargetType="UserControl">
<Style.Triggers>
<DataTrigger Binding="..." Value="...">
<Setter Property="RenderTransform.ScaleX" Value="0.5" />
<Setter Property="RenderTransform.ScaleY" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
</UserControl>
But when I compile, I get the error:
Cannot resolve the Style Property 'ScaleX'. Verify that the owning
type is the Style's TargetType, or use Class.Property syntax to
specify the Property.
I've tried all sorts of permutations of the Property but I can't find one that actually works. In other cases, I'll just name the ScaleTransform and reference that with TargetName. But you can't use TargetName in a Style Setter.
I guess my alternative is something like this:
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
</Setter.Value>
</Setter>
But that seems a little heavy-handed.
I'm sure I'm just missing something. But I could really use some help here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Setter 不允许属性路径。如果您的场景允许,它会用一个新的转换来切换整个转换。或者,您可以使用更重的单帧动画。
Setters do not allow property paths. If your scenario allows it switch out the whole transform with a new one. Alternatively you can use a single frame animation, which is even heavier.