locked
How many items in a WrapGrid row at runtime?

    Question

  • Hi,

    Is there a way to get the number of items that have been rendered per row at run time without calculating based on the width of the container and the width of the items?

    Thanks

    Brian

    Thursday, December 4, 2014 7:44 PM

Answers

  • get  ActualWidth , ActualHeight of container  then set  WrapGrid.MaximumRowsOrColumns Property


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。


    • Edited by Bill ChungMVP Thursday, December 4, 2014 8:16 PM
    • Marked as answer by duffybr Thursday, December 4, 2014 8:29 PM
    Thursday, December 4, 2014 8:14 PM

All replies

  • get  ActualWidth , ActualHeight of container  then set  WrapGrid.MaximumRowsOrColumns Property


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。


    • Edited by Bill ChungMVP Thursday, December 4, 2014 8:16 PM
    • Marked as answer by duffybr Thursday, December 4, 2014 8:29 PM
    Thursday, December 4, 2014 8:14 PM
  • Good idea, thanks Bill. I'll just decide based on the actual size of the container how many should be in there and go with that.
    Thursday, December 4, 2014 8:30 PM
  • sample

    xaml

    <Page
        x:Class="App2.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App2"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="grid" >
            <ListView x:Name="listview">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapGrid Orientation="Horizontal" Loaded="WrapGrid_Loaded"   />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
    
                <Rectangle Height="300" Width="300" Fill="Blue" />
                <Rectangle Height="300" Width="300" Fill="Red" />
                <Rectangle Height="300" Width="300" Fill="Yellow" />
                <Rectangle Height="300" Width="300" Fill="Green" />
                <Rectangle Height="300" Width="300" Fill="Gray" />
                <Rectangle Height="300" Width="300" Fill="LightBlue" />
                <Rectangle Height="300" Width="300" Fill="Pink" />
                <Rectangle Height="300" Width="300" Fill="YellowGreen" />
                <Rectangle Height="300" Width="300" Fill="Blue" />
                <Rectangle Height="300" Width="300" Fill="Red" />
                <Rectangle Height="300" Width="300" Fill="Yellow" />
                <Rectangle Height="300" Width="300" Fill="Green" />
                <Rectangle Height="300" Width="300" Fill="Gray" />
                <Rectangle Height="300" Width="300" Fill="LightBlue" />
                <Rectangle Height="300" Width="300" Fill="Pink" />
                <Rectangle Height="300" Width="300" Fill="YellowGreen" />
            </ListView>
        </Grid>
    </Page>
    

    C#
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
    
            private void WrapGrid_Loaded(object sender, RoutedEventArgs e)
            {
                  double h = grid.ActualWidth;
                  int count =(int) (h / 300);
                  Debug.WriteLine(count);
                ((WrapGrid)sender).MaximumRowsOrColumns =count;
            }
        }



    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Thursday, December 4, 2014 8:36 PM
  • and there it is :-)
    Thursday, December 4, 2014 8:45 PM