gpt4 book ai didi

c# - ChildWindow 宽度/高度未正确绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-03 19:24:12 24 4
gpt4 key购买 nike

我试图将我的子窗口设置为我的应用程序的大小,以便它占据整个屏幕。我正在使用以下代码:

Binding widthBinding = new Binding("Width");
widthBinding.Source = App.Current.Host.Content.ActualWidth;
this.SetBinding(ChildWindow.WidthProperty, widthBinding);

Binding heightBinding = new Binding("Height");
heightBinding.Source = App.Current.Host.Content.ActualHeight;
this.SetBinding(ChildWindow.HeightProperty, heightBinding);

this 是子窗口。

我正在绑定(bind)它,以便当他们调整浏览器大小时,子窗口也应该如此。但是,我的子窗口不受尺寸限制。它仍然保持其默认大小。我的绑定(bind)不正确吗?

最佳答案

我不相信你会开始工作。让您的 ChildWindow 填满屏幕的最简单方法是将 Horizo​​ntalAlignment 和 VerticalAlignment 设置为 Stretch

<controls:ChildWindow x:Class="SilverlightApplication4.ChildWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Title="ChildWindow1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

如果您绝对想在 silverlight 中使用 ActualWidth/ActualHeight 路线,则必须执行类似...

public ChildWindow1()
{
InitializeComponent();

UpdateSize( null, EventArgs.Empty );

App.Current.Host.Content.Resized += UpdateSize;
}

protected override void OnClosed( EventArgs e )
{
App.Current.Host.Content.Resized -= UpdateSize;
}

private void UpdateSize( object sender, EventArgs e )
{
this.Width = App.Current.Host.Content.ActualWidth;
this.Height = App.Current.Host.Content.ActualHeight;
this.UpdateLayout();
}

关于c# - ChildWindow 宽度/高度未正确绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10015145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com