gpt4 book ai didi

xaml - 绑定(bind)到 XAML 中的 Window.Current.Bounds.Width

转载 作者:行者123 更新时间:2023-12-04 23:05:26 24 4
gpt4 key购买 nike

我在 LayoutAware 页面上有一个弹出控件。

我真正想要的是让弹出窗口填满屏幕。

我认为解决方案是使用 Window.Current.Bounds.Height/Width 在弹出控件内的网格​​上设置相应的属性。

我不想使用文件后面的代码来设置这些属性。我希望能够绑定(bind)到 XAML 中的 Window.Current.Bounds.Height。

我可以这样做吗?

有没有更好的方法让弹出窗口填满屏幕?

最佳答案

您可以通过编写高度和宽度的转换器来做到这一点。

public class WidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return Window.Current.Bounds.Width;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class HeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return Window.Current.Bounds.Height;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

将此添加到您的页面资源部分 -
    <common:WidthConverter x:Key="wc" />
<common:HeightConverter x:Key="hc" />

将它们用于您的弹出窗口 -
        <Popup x:Name="myPopup"  >
<Grid Background="#FFE5E5E5" Height="{Binding Converter={StaticResource hc}}" Width="{Binding Converter={StaticResource wc}}" />
</Popup>

关于xaml - 绑定(bind)到 XAML 中的 Window.Current.Bounds.Width,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13466747/

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