- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 ListBox
在我的 View 中显示 ObservableCollection
的内容。在我的简化示例中,我只是为每个项目使用一个图像,如下所示:
<Window>
<Window.Resources>
<DataTemplate DataType="{x:Type viewModel:HealthCriterionViewModel}">
<Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="Optionsh.png" Stretch="Fill" />
</DataTemplate>
</Window.Resources>
<ListBox ItemsSource="{Binding HealthCriteria}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Window>
HealthCriteria
是 HealthCriterionViewModel
类型的集合。
我得到的是这样的:
我想要的是这个(拉伸(stretch)图像以在垂直和水平方向上使用所有可用空间):
我怎样才能做到这一点?
最佳答案
我建议你不能用ItemsControl来实现。因为内容展示器大小不固定,所以它是可滚动区域。所以每个元素的大小应该是固定的。它可以直接在具有“重量”或“高度”(取决于方向)属性的 ItemsPanel 中进行限制,或者受内容大小限制。
关于c# - 使用 ListBox 和 StackPanel 的所有可用空间作为 ItemsPanelTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33365754/
我需要设置 ItemsPanelTemplate ListBox 的属性基于 DependencyProperty在控件上。我如何使用 DataTemplateSelector要做到这一点? 我有类似
如果我想将 ItemsPanelTemplate 从默认 (StackPanel) 更改为 Grid
我有一个 ListView,它的布局看起来像一个 Windows 资源管理器 View (图标 + 一些细节),绑定(bind)到 ViewModel 中某处的列表。 我的目标是能够随时在资源管理器
我正在 Silverlight 中构建一个自定义 ItemsControl(除其他外),它允许项目在运行时水平或垂直显示。如何将 ItemsPanel 的 Orientation 属性绑定(bind)
我在 XAML 中定义了这个 UserControl 并且想在我的代码隐藏类中动态设置 ItemsPanelTemplate(不在XAML 就像示例中一样):
我创建了一个用户控件,其中包含一个带有自定义 ItemsPanelTemplate 的 ListView。 ...
我用过 ItemsPanelTemplate在其他控件上,例如 ListBox ,所以我想对 TabControl 做同样的事情会很简单。 显然,我遗漏了一些东西和 TabControl完全无视我放在
我想在 WPF 中添加一个 Grid 作为 ItemsControl 的 ItemPanelTemplate。 我知道有很多类似的问题。但到目前为止,我所看到的所有这些都在谈论动态添加行和列,但它们并
我想在运行时更改 ListBox 的 ItemsPanelTemplate。 我有以下 XAML,它允许我更改 ItemsPanelTemplate;但是有破坏 ScrollViewer 的不良副作用
我需要根据控件的依赖属性设置列表框的 ItemsPanelTemplate 属性。我如何使用 DataTemplateSelector 来做到这一点? 我有这样的东西:
我正在尝试覆盖 Silverlight 中 TabControl 的默认模板。我不想让标签在它们满时环绕,而是想让用户可以滚动浏览它们,类似于 ListBox。但是,Silverlight 会忽略我在
我正在处理一个动态创建的网格,在每个新列中包含一个添加到 ItemsControl 的新项目。 我正在使用 Rachel Lim 的 GridHelper 现在,我有一个如下所示的主窗口, Xaml
我正在尝试创建与组合框相关的混合行为。为了获得我想要的效果,ComboBox 的 ItemsPanel 必须添加特定的元素。我不想在每个使用该行为的 ComboBox 中都这样做,所以我希望 Beha
那么如果我有一个items控件,想在后面的代码中获取 Canvas ,我该怎么办?我可以获得 itemscontrol,但是我该怎么做才能检索 Canvas ?我试过了 Canvas c1 = ic.
当 ItemsControl 被 ItemsSource 绑定(bind)时,我正在尝试访问 DataTemplate 内的 Grid。 这是完整的 XMAL 代码,我如何从外部找到某个元素? for
我正在尝试像这样修改我的 WrapGrid 的 MaximumRowsOrColumns 属性: 然后我使用此代码更改 WrapGrid:
我一直在开发我的第一个 MVVM WPF 应用程序,我想在其中绘制一个包含节点和边的图形。目前,我正在 View 后面的代码中执行所有绘图逻辑,迭代节点,相应地创建形状并将它们添加到 Canvas 中
我使用 ListBox 在我的 View 中显示 ObservableCollection 的内容。在我的简化示例中,我只是为每个项目使用一个图像,如下所示:
我有一个自定义面板,我在其中声明了一个自定义属性来保存内容(我不想为内容使用子项): [ContentProperty(Name = "PanelContent")] public class Cus
我是一名优秀的程序员,十分优秀!