将索引数组中的更多列绑定到一个Scrollviewer WPF中 - C#

时间:2023-01-28 12:32:07

I need to bind an array of objects in ItemsSource , but not bind in the standard way , ie on row , but on columns , so two different xaml objects in succession . Let me explain, I now have solved so :

我需要在ItemsSource中绑定一个对象数组,但不是以标准方式绑定,即在行上,而是在列上绑定,因此连续两个不同的xaml对象。让我解释一下,我现在已经解决了这个问题:

将索引数组中的更多列绑定到一个Scrollviewer WPF中 -  C#

but I would need to turn the view and make it to the grid as well :

但我需要转动视图并将其转换为网格:

将索引数组中的更多列绑定到一个Scrollviewer WPF中 -  C#

In this case I have two objects to bind to each row , so I find it hard bindare objects from the array in succession on two different columns at the same time , my xaml code :

在这种情况下,我有两个对象绑定到每一行,所以我发现它同时在两个不同的列上连续地绑定数组中的对象,我的xaml代码:

<surface:SurfaceScrollViewer x:Name="listDocumentsVisibility" Visibility="Visible" Grid.Column="1" Grid.Row="0" Margin="15,36,15,35" Background="GhostWhite" VerticalScrollBarVisibility="Hidden" PanningMode="Both">
                <ItemsControl ItemsSource="{Binding Path=AttachmentsFileList}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <surface:SurfaceButton Tag="{Binding ATID}" Click="Meeting_Click">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <StackPanel>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="60"/>
                                        </Grid.RowDefinitions>
                                                <StackPanel Grid.Row="0" Margin="10,5,0,0" Grid.Column="0">
                                                    <Image Width="26" Margin="5,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Source="/Resources/Images/icon-document-browser.png"></Image>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-30,0,0" FontSize="12" Text="{Binding Name}"></TextBlock>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-15,0,0" FontSize="9" Foreground="#6C6C6C" Text="{Binding LastOpenDate}"></TextBlock>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-3,0,0" FontSize="9" Foreground="#6C6C6C" Text="istituto"></TextBlock>
                                                </StackPanel>
                                                <StackPanel Grid.Row="0" Margin="10,5,0,0" Grid.Column="1">
                                                    <Image Width="26" Margin="5,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Source="/Resources/Images/icon-document-browser.png"></Image>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-30,0,0" FontSize="12" Text="{Binding Name}"></TextBlock>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-15,0,0" FontSize="9" Foreground="#6C6C6C" Text="{Binding LastOpenDate}"></TextBlock>
                                                    <TextBlock FontFamily="{StaticResource Lato Light}" HorizontalAlignment="Left" Margin="38,-3,0,0" FontSize="9" Foreground="#6C6C6C" Text="istituto"></TextBlock>
                                                </StackPanel>
                                            </Grid>
                                </StackPanel>
                            </ControlTemplate>
                        </Button.Template>
                    </surface:SurfaceButton>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </surface:SurfaceScrollViewer>  

obviously the whole is dynamic , depending on the rest call I receive.

显然整体是动态的,取决于我收到的其他电话。

can bind two array index , one next to another in the same row ? Thank you

可以绑定两个数组索引,一个在同一行旁边?谢谢

1 个解决方案

#1


0  

Use an ItemsControl and set the ItemsPanel to be a UniformGrid with Columns=2, just make sure you set VerticalAlignment="Top" so that the items don't get stretched out and wrap the whole thing in a ScrollViewer if you need to:

使用ItemsControl并将ItemsPanel设置为具有Columns = 2的UniformGrid,只需确保设置VerticalAlignment =“Top”,这样物品就不会伸展出来并将整个事物包装在ScrollViewer中,如果您需要:

<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
    <ItemsControl ItemsSource="{Binding MyItems}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="2" VerticalAlignment="Top" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</ScrollViewer>

#1


0  

Use an ItemsControl and set the ItemsPanel to be a UniformGrid with Columns=2, just make sure you set VerticalAlignment="Top" so that the items don't get stretched out and wrap the whole thing in a ScrollViewer if you need to:

使用ItemsControl并将ItemsPanel设置为具有Columns = 2的UniformGrid,只需确保设置VerticalAlignment =“Top”,这样物品就不会伸展出来并将整个事物包装在ScrollViewer中,如果您需要:

<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
    <ItemsControl ItemsSource="{Binding MyItems}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="2" VerticalAlignment="Top" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</ScrollViewer>