WPF MaterialDesignInXamlToolkit 对话框扩展到全宽 [英] WPF MaterialDesignInXamlToolkit Dialog expand to full width
问题描述
我试图让 DialogHost 中的对话框尽可能地水平拉伸,而不对我正在显示的控件的大小进行硬编码.
I'm trying to get the dialog in DialogHost to be horizontally stretched as much as possible, without hardcoding the size of the control that I'm displaying.
尝试了以下方法:
- 将 UserControl.HorizontalAligment 设置为 Stretch
- 在 DialogHost 上将 HorizontalContentAligment 设置为拉伸
我注意到,如果将 Width 设置为 6000 之类的值,对话框会用一些漂亮的填充填充 DialogHost,但内容会溢出并且右侧的东西不可见.
I noticed that if set the Width to something like 6000, the dialog fills the DialogHost with some nice padding, but the content overflows and things on the right side are not visible.
是否有一些标准方法可以实现这一目标?
Is there some standard way to achieve this?
我最终这样做了并且它有效,但也许有更好的方法
I ended up doing this and it works, but maybe there is a better way
// in ControlShowedInDialog.xaml.cs
this.WhenActivated(d =>
{
var window = Window.GetWindow(this);
window.WhenAnyValue(x => x.ActualWidth).Throttle(TimeSpan.FromMilliseconds(10), RxApp.MainThreadScheduler).Do(width => Width = width * 0.85).Subscribe().DisposeWith(d);
window.WhenAnyValue(x => x.ActualHeight).Throttle(TimeSpan.FromMilliseconds(10), RxApp.MainThreadScheduler).Do(height => Height = height * 0.75).Subscribe().DisposeWith(d);
推荐答案
尝试使用 RelativeSource
绑定与 DialogHost
的 ActualWidth
绑定.
Try using RelativeSource
binding to bind with DialogHost
's ActualWidth
.
将此设置为您的UserControl
,
...
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
...
Width="{Binding Path=ActualWidth,
RelativeSource={RelativeSource AncestorType={x:Type wpf:DialogHost},
Mode=FindAncestor}}"
如果您还需要更多调整,可以使用 IValueConverter
来实现.
If you still need some more adjustments, you can use IValueConverter
to achieve that.
这篇关于WPF MaterialDesignInXamlToolkit 对话框扩展到全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!