【发布时间】:2018-07-19 09:07:21
【问题描述】:
我有一个问题,如何在 WPF 应用程序中按行移动对象?我的 Xaml 如下所示:
<Grid>
<Grid.ColumnDefinitions>
<Some columns here!/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<Some Rows here!/>
</Grid.RowDefinitions>
<Button x:Name="Button1"
Grid.Row="1" Grid.Column="4"
Width="50" Height="50"
Content="Button1"
Foreground="White"
BorderThickness="0"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
BorderBrush="{x:Null}"
Background="#FF085078"/>
<Button x:Name="Button2"
Grid.Row="2" Grid.Column="4"
Content="Button2"
Foreground="White"
BorderThickness="0"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
BorderBrush="{x:Null}"
Background="#FF085078"/>
<ContentControl Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Grid.ColumnSpan="3"
x:Name="ActiveItem"/>
我想要做的是,当我在内容控件中显示另一个窗口时,我想从内容控件的第二个视图下移动“Button2”。如何在内容控制下移动项目,当我关闭第二个视图时,项目会回到它们的主要位置?如何绑定 Grid.Row 以做我想做的事?如果有帮助,我正在使用 Caliburn.Micro 框架>
感谢您的建议!
【问题讨论】:
-
Grid.SetRow(Button2, 3);不是你想要的? -
您还可以将 Grid.Row 绑定到可绑定属性
-
@Clemens 是的,这正是我想要的!
-
@Bijan 你能解释一下如何正确绑定 SetRow 吗?我打赌我需要创建移动对象的方法,然后在显示 ContentControl 的方法中调用该方法来移动对象
-
如果您想在 ContentControl 的 Content 为非 null 时移动 Button,您还可以使用带有 DataTrigger 的 Button Style 作为纯 XAML 解决方案。
标签: c# wpf xaml mvvm caliburn.micro