UWP: Popup MaxWidth

亡梦爱人 提交于 2019-12-11 04:25:31

问题


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.

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>

Thanks...


回答1:


I partially solve this problem by forcing the width.

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.

Thanks!



来源:https://stackoverflow.com/questions/37209628/uwp-popup-maxwidth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!