我想在我的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值只允许我指定一个。
答案 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"