Setter.Target 给我一个错误“RelativePanel.AlignHorizontalCenterWithPanel"; [英] Setter.Target give me an error with "RelativePanel.AlignHorizontalCenterWithPanel"
问题描述
我正在开发一个 UWP 应用,我正在使用 Template10.我有一个 TextBlock
,在 VisualStateNarrow
我想要它 RelativePanel.AlignVerticalCenterWithPanel="True"
和在 NormalMinWidth
我想要 RelativePanel.AlignHorizontalCenterWithPanel="True"
但我不能这样做!
I am develop an UWP app, and I am using Template10.
I have an TextBlock
, that in VisualStateNarrow
I want it RelativePanel.AlignVerticalCenterWithPanel="True"
and in NormalMinWidth
I want RelativePanel.AlignHorizontalCenterWithPanel="True"
but I can not do this!
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveVisualStateGroup">
<VisualState x:Name="VisualStateNarrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TextBlock.RelativePanel.AlignVerticalCenterWithPanel="True"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateNormal">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TextBlock.RelativePanel.AlignHorizontalCenterWithPanel="True"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWidth}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
在 XAML 编辑器中给我这个错误:抛出异常."- 无法解析指定对象上的 TargetProperty RelativePanel.AlignHorizontalCenterWithPanel."
In XAML editor give me this error: "An Exception was thrown." - "Cannot resolve TargetProperty RelativePanel.AlignHorizontalCenterWithPanel on specified object."
我有很多 Setter.Target 并且它们都有效!我的 Setter.Target 示例:
I have many Setter.Target and they all work! Example of my Setter.Target:
<Setter Target="TextBlock.Margin" Value="8"/>
<Setter Target="TextBlock.Width" Value="200"/>
<Setter Target="TextBlock.Height" Value="200"/>
推荐答案
对于附加属性,您必须在 setter 中添加括号,如下所示:
For attached properties you have to add brackets to in setters as follows:
Element.(Grid.Row)
Element.(ToolTipService.ToolTip)
所以你的代码看起来像这样:
So your code will look like this:
<Setter Target="TextBlock.(RelativePanel.AlignVerticalCenterWithPanel)" Value="True" />
这篇关于Setter.Target 给我一个错误“RelativePanel.AlignHorizontalCenterWithPanel";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!