UWP:弹出MaxWidth [英] UWP: Popup MaxWidth

查看:76
本文介绍了UWP:弹出MaxWidth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口,其中包含一个ItemsControl(如果需要,我可以使用ListBox),其项目水平排列.

I have a Popup which contains an ItemsControl (I can use ListBox if needed) which its items are arranged horizontally.

由于项目的总宽度可以超过屏幕的宽度,所以我需要限制弹出窗口的宽度.

Since the total width of the items can exceed the width of the screen, I need to limit the size of the popup width.

我的问题是如何限制弹出窗口的大小?我尝试使用MaxWidth,但是它不起作用:(

My question is how can I limit the size of the popup? I've tried to use MaxWidth, but it doesn't work :(

<Popup x:Name="puSoldItems" IsOpen="False" IsLightDismissEnabled="True" MaxWidth="{Binding ActualWidth, ElementName=_This}" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto">
    <Grid Background="#f8202020" MaxWidth="{Binding ActualWidth, ElementName=puSoldItems}">
        ...
        ...
        ...
        <ItemsControl x:Name="icItems" Grid.Row="1" Background="Transparent" Margin="10" MaxWidth="{Binding ActualWidth, ElementName=puSoldItems}" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto">
            ...
            ...
            ...
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Padding="0" Margin="0 0 0 10" BorderBrush="#afafaf" BorderThickness="0 0 0 1" MinWidth="350">
                        ...
                        ...
                        ...
                        <local:UPSoldItemList ItemsSource="{Binding Items}"></local:UPMenuModifier>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</Popup>

谢谢...

推荐答案

我通过强制宽度来部分解决此问题.

I partially solve this problem by forcing the width.

这就是我所做的;我添加ScrollViewer并将ItemsControl放入其中.然后,当打开弹出窗口时,我设置ScrollViewer的大小

Here is what I did; I add ScrollViewer and put ItemsControl inside. Then when open the popup, I set the size of the ScrollViewer

private void btnItem_Tapped(object sender, TappedRoutedEventArgs e)
{
    svItems.MaxWidth = this.ActualWidth - 100;    //for padding (50 left & 50 right)
    svItems.MaxHeight = this.ActualHeight - 80;   //for padding (40 top & 40 bottom)
    puSoldItems.IsOpen = true;
}

有没有更好的解决方案,请在此处发布.

Is anyone has a better solution, please kindly post it here.

谢谢!

这篇关于UWP:弹出MaxWidth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆