【发布时间】:2019-05-23 14:39:26
【问题描述】:
我正在构建一个 UWP 应用。我正在使用一个 Rectangle XAML 元素,我在 XAML 代码中为其指定了一个定位属性-RelativePanel.RightOf()。现在单击特定按钮时,我需要将 Rectangle 从其原始位置移动到其他控件的左侧。所以在接收到 Click 事件时,我使用属性 RelativePanel.SetLeftOf() 来移动它。
XAML 代码-
<StackPanel>
<RelativePanel Height="50" Width="200">
<Rectangle x:Name="_redRect" Height="50" Width="50" Fill="Red" RelativePanel.AlignLeftWithPanel="True"/>
<Rectangle x:Name="_blueRect" Height="50" Width="50" Fill="Blue" RelativePanel.RightOf="_redRect"/>
<Rectangle x:Name="_greenRect" Height="50" Width="50" Fill="Green" RelativePanel.AlignRightWithPanel="True"/>
</RelativePanel>
<Button x:Name="_switch" Click="OnSwitchClicked">Switch</Button>
</StackPanel>
C#代码-
private void OnSwitchClicked(object sender, RoutedEventArgs e)
{
RelativePanel.SetLeftOf(_blueRect, _greenRect);
}
但这并不能解决我的问题。 _blueRect 似乎位于 _redRect 和 _greenRect 的中间。这可能是因为第一个约束 RelativePanel.LeftOf = "_redRect" 尚未删除。如何通过代码移除该约束?
还有没有什么方法可以一起去掉所有的定位约束?
【问题讨论】:
-
展示和讲述。向我们展示您尝试过的内容(意味着您已经努力实际编写您需要的代码),具体来说是遇到了什么。 ...而且...我们会告诉答案:)
-
@Epistaxis 完成