c# - 在 WPF 中放入像 Html Float Resource 这样的图片

标签 c# html css .net wpf

在 html 中,我可以创建一个 div 并用放置在 float 位置的图像填充它:

<div style="width: 560px; height: 560px;">
    <img src="myurl" style="width: 100px; height: 100px; float: left;" />
    <img src="myurl" style="width: 100px; height: 100px; float: left;" />
    <img src="myurl" style="width: 100px; height: 100px; float: left;" />
    ...
</div>

我正在尝试在 WPF 中做同样的事情:

首先我尝试像这样使用 StackPanel:

<StackPanel>
    <Image Source="myurl" Width="100" Height="100" />
    <Image Source="myurl" Width="100" Height="100" />
    ...
</StackPanel>

没有成功,似乎这个组件只是在一个方向上堆叠对象。

接下来我尝试使用 ListView:

<ListView Background="#5a5a5a">
    <ListViewItem Width="100" Height="100">
        <Image Source="myurl" Width="100" Height="100" />
    </ListViewItem>
    <ListViewItem Width="100" Height="100">
        <Image Source="myurl" Width="100" Height="100" />
    </ListViewItem>
</ListView>

但所有图像都保持在中心位置。

如何使用 WPF 实现 html float 的相同效果?

最佳答案

我想你在找WrapPanel class . 来自 MSDN:

Positions child elements in sequential position from left to right, breaking content to the next line at the edge of the containing box. Subsequent ordering happens sequentially from top to bottom or from right to left, depending on the value of the Orientation property.

换行面板与 StackPanel 类似,但它不只是将所有子元素堆叠到一行,如果没有剩余空间,它会将它们换行。方向可以设置为水平或垂直。

WrapPanel 可用于排列选项卡控件的选项卡、工具栏中的菜单项或 Windows 资源管理器(如列表)中的元素。 WrapPanel 通常用于相同大小的元素,但这不是必需的。 ( Source )

关于c# - 在 WPF 中放入像 Html Float Resource 这样的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36464400/

相关文章:

jquery - 为菜单/导航栏制作滚动按钮

c# - 删除给定索引处的列表元素

c# - 多个客户端之间的对象同步算法

html - jQuery Mobile 类似 iPhone 的图片库

javascript - 一种元素的 JS 事件监听器?

html - 使用 CSS 单击其他卡片时返回 Flipkart

html - 如何将文本右对齐到列中?

c# - 在没有 OleDbConnection 或 Interop 的情况下在 C# 中访问 Excel

c# - 在输入 API 请求中发现未知属性时抛出错误?

c# - 在 C# 中用 Regex 替换两个或多个空格