首页 > 解决方案 > Uniformgrid 按列表计数动态排列,如何填充左侧

问题描述

这里列表计数= 11

我要从左到右填充

但是当我申请时并没有什么不同

WPF 代码

        <Border x:Name="LogoListBorder" BorderBrush="#c7c7c7" BorderThickness="1">
            <ItemsControl x:Name="ControlLogo" ItemsSource="{Binding}" 
              VerticalAlignment="Top" FlowDirection="LeftToRight" >
                <ItemsControl.ItemTemplate >
                    <DataTemplate DataType="{x:Type mo:LogoModel}">
                        <Grid>                                  
                            <Button x:Name="LogoButton" 
                            Tag="{Binding LogoIndex}"
                            Width="{Binding LogoWidth}" 
                            Height="{Binding LogoHeight}" 
                            Panel.ZIndex="0"  >
                                <Grid x:Name="LogoGrid" >
                                    <Image 
                                      Width="{Binding LogoWidth}" 
                                      Height="{Binding LogoHeight}" 
                                      Source="{Binding LogoImage}" 
                                      Tag="{Binding LogoCode}" 
                                      RenderOptions.BitmapScalingMode="Fant" 
                                      HorizontalAlignment="Center"                                                                                     
                                      VerticalAlignment="Center"/>
                                        
                                        <TextBlock  Text="{Binding LogoName}"                                                                                         
                                         VerticalAlignment="Center"
                                         HorizontalAlignment="Center"
                                         TextAlignment="Center"
                                         FontWeight="Bold"
                                         FontSize="19" />
                                    </Grid>
                            </Button>

                            
                            <Grid x:Name="EveningGrid" 
                                         Width="{Binding EveningGridWidth}"
                                         Height="{Binding EveningGridHeight}"
                                         VerticalAlignment="Top"
                                         HorizontalAlignment="Left"
                                         Panel.ZIndex="1">
                                <Border BorderThickness="1" 
                                        Margin="{Binding                                             
                                        EveningBorderMargin}">                      
                                </Border>
                            </Grid>
                            <!--#endregion-->
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>                                
                        <!-- Behind Code UniformGrid-->
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter Property="FrameworkElement.Margin" Value="0"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
            </ItemsControl>
        </Border>

Uniformgrid 动态集背后

FrameworkElementFactory ug = new FrameworkElementFactory(typeof(UniformGrid));
                ControlLogo.ItemsPanel = new ItemsPanelTemplate(ug);

                if (LogoListCount < 11)
                {
                    ug.SetValue(UniformGrid.RowsProperty, 10); //Row Setting
                    ug.SetValue(UniformGrid.ColumnsProperty, 1); //Row Setting
                }
                else if (LogoListCount <= 20 && LogoListCount >= 11)
                {
                    ug.SetValue(UniformGrid.ColumnsProperty, 2; //Row Setting
                    ug.SetValue(UniformGrid.RowsProperty, 10); //Row Setting                    
                }
                else 
                {
                    ug.SetValue(UniformGrid.RowsProperty, 10); //Row Setting
                    ug.SetValue(UniformGrid.ColumnsProperty, 3); //Row Setting

                }

但是......就像图片一样,为什么不填充左行第 7~11 行?我不.. 不工作 UniformGrid FlowDirection LeftToRight.. 我想填充左行 LineNumber 7~11, Ater next clomn

在此处输入图像描述

标签: wpf

解决方案


推荐阅读