将XAML中的Anchor值设置为Left,Right,Top,Bottom

时间:2015-08-24 08:51:30

标签: c# wpf winforms anchor

我想在我的WPF项目中使用WinForms DateTimePicker。

这适用于下面的xaml。

<WindowsFormsHost HorizontalAlignment="Left" Height="34" Margin="10,10,0,-44" VerticalAlignment="Top" Width="280">
    <wf:DateTimePicker Name="DateTimePickerBox" Dock="Fill" Anchor="Right" />
</WindowsFormsHost>

在Winforms项目中如果我想锚定到Left,Right,Top和Bottom,我会使用下面的代码。

this.dateTimePicker1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));

我如何在XAML中执行此操作,因为Anchor值只允许我指定一个。

2 个答案:

答案 0 :(得分:1)

使用逗号

<WindowsFormsHost HorizontalAlignment="Left" Height="34" Margin="10,10,0,-44" VerticalAlignment="Top" Width="280">
      <wf:DateTimePicker Name="DateTimePickerBox" Dock="Fill" Anchor="Right,Left,Bottom,Top" />
</WindowsFormsHost>

答案 1 :(得分:0)

而不是Anchor="Right"只需写下 Anchor="Top, Bottom, Left, Right"