将 XAML 中的锚点值设置为左、右、上、下
Setting Anchor value in XAML to Left, Right, Top, Bottom
我想在我的 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 项目中,如果我想锚定到左、右、上和下,我将使用以下代码。
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 中执行此操作,因为锚值只允许我分配一个。
使用逗号
<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>
而不是 Anchor="Right"
只需写 Anchor="Top, Bottom, Left, Right"
我想在我的 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 项目中,如果我想锚定到左、右、上和下,我将使用以下代码。
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 中执行此操作,因为锚值只允许我分配一个。
使用逗号
<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>
而不是 Anchor="Right"
只需写 Anchor="Top, Bottom, Left, Right"