简体   繁体   English

如何在 WPF 中创建“响应式图像网格”

[英]How to create a “Responsive Image Grid” in WPF

Good day!再会! I want to make a scrollable image grid like "Unsplash" site, but with WPF.我想制作一个像“Unsplash”网站一样的可滚动图像网格,但使用 WPF。 I using Grid and ListBoxes, but the Grid not scrolling, scrolling only 3 ListBoxes apart from each other.我使用网格和列表框,但网格不滚动,仅滚动 3 个彼此分开的列表框。 What I should use for that type of thing?我应该用什么来做那种事情?

What I need我需要的

在此处输入图片说明

What I have with wrong scrolling我有什么错误滚动

在此处输入图片说明

WPF code: WPF代码:

<Grid ScrollViewer.VerticalScrollBarVisibility="Visible">
    <Grid.ColumnDefinitions>
        <ColumnDefinition>
         
        </ColumnDefinition>
            <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <ListBox Grid.Column="0" x:Name="listBox0" ScrollViewer.VerticalScrollBarVisibility="Disabled">

    </ListBox>

    <ListBox Grid.Column="1" x:Name="listBox1" ScrollViewer.VerticalScrollBarVisibility="Disabled">

    </ListBox>

    <ListBox Grid.Column="2" x:Name="listBox2" ScrollViewer.VerticalScrollBarVisibility="Disabled">

    </ListBox>
</Grid>

List filling:列表填写:

for (int i = 0; i < 20; i++)
        {
            Rectangle temp = new Rectangle();
            temp.Width = 250;
            temp.Height = rnd.Next(100, 300);
            temp.Fill = GetRandColor();

            if(listStateCounter == 2)
            {
                listStateCounter = 0;
                listBox2.Items.Add(temp);
            }
            else if (listStateCounter == 1)
            {
                listStateCounter++;
                listBox1.Items.Add(temp);
            }
            else if (listStateCounter == 0)
            {
                listStateCounter++;
                listBox0.Items.Add(temp);
            }

        }

try this试试这个

<ScrollViewer VerticalScrollBarVisibility="Visible">
  <Grid>
    //.............................................
  </Grid>
</ScrollViewer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM