C# 动态绑定行定义数到ItemsPanelTemplate中的网格

C# 动态绑定行定义数到ItemsPanelTemplate中的网格,c#,wpf,xaml,C#,Wpf,Xaml,我已经编写了xaml,用于在3列的网格中显示视频文件。我使用的xaml如下: <ItemsControl Name="icTodoList" Grid.IsSharedSizeScope="True" ItemsSource="{Binding items}" Grid.Row="0" Grid.Column="0" > <ItemsControl.ItemsPanel>

我已经编写了xaml,用于在3列的网格中显示视频文件。我使用的xaml如下:

     <ItemsControl  Name="icTodoList" Grid.IsSharedSizeScope="True" ItemsSource="{Binding items}" Grid.Row="0" Grid.Column="0" >
                        <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate >
                                    <Grid  x:Name="icTooList" Margin="100,0,100,0" Style="{Binding Path=Style}">
                                    <Grid.ColumnDefinitions>
                                        <!--Whatever I do I can't get the screen to resize and the cols to have the same width-->
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />
                                    </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
                                    </Grid.RowDefinitions>
                                </Grid>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="40,0,40,30">
                                    <TextBlock HorizontalAlignment="Center" Margin="0,0,0,0">
                                           <Hyperlink TextDecorations="None" NavigateUri="{Binding UriPath}" RequestNavigate="Hyperlink_RequestNavigate"
                                                      CommandParameter="{Binding ElementName=myImg}">
                                                            <Image Width="120" Height="120"  x:Name="myImg" Source="{Binding Source}" Margin="5"/>
                                           </Hyperlink>
                                    </TextBlock>
                                    <TextBlock Margin="0,120,0,0" HorizontalAlignment="Center">
                                                <TextBlock FontSize="20px" Text="{Binding Title}" Foreground="white"></TextBlock>
                                        </TextBlock>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Style.Setters>
                                    <Setter Property="Grid.Row" Value="{Binding GridRow}" />
                                    <Setter Property="Grid.Column" Value="{Binding GridColumn}" />
                                </Style.Setters>
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                    </ItemsControl>
但我需要在网格中动态绑定这个行定义。我试过下面的一个,但不适合我。对以下问题发表评论,无人回答


我已经使用了UniformGrid并绑定了行,下面是动态绑定行的代码

Xaml:

 <UniformGrid Columns="3" Rows="{Binding RowCount}">
  </UniformGrid>

C#

List items1=新列表();
int currentRow=10;
items1.Add(newpartlist(){RowCount=currentRow});
公共类部件列表
{
公共int行计数{get;set;}
}

我认为您链接的响应就是您需要的响应,只需按照其中链接的附加属性的官方指南操作即可。您可以发布您想要编写的语法吗?我不知道如何编写。。我需要根据行数多次添加行定义。使用
作为面板而不是修补网格如何?请始终记住,最好包括您当前的方法(如您所做的),但也要询问您实际需要的内容(您需要特定的布局,但询问动态网格行定义)。
 void setaligned()
            {
                int currentColumn = 0;
                int currentRow = 0;

                foreach (BindingFilesContent checkBoxItem in items)
                {
                    checkBoxItem.GridColumn = currentColumn;
                    checkBoxItem.GridRow = currentRow;
                    if (currentColumn != 2)
                    {
                        currentColumn++;
                    }
                    else
                    {
                        currentRow++;
                        currentColumn = 0;
                    }
            }
}
 <UniformGrid Columns="3" Rows="{Binding RowCount}">
  </UniformGrid>
List<PartList> items1 = new List<PartList>();

 int currentRow = 10;

 items1.Add(new PartList() { RowCount = currentRow });

public class PartList
{
            public int RowCount { get; set; }
}