- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想写一个 ItemsControl 派生的自定义控件。这部分是出于需要,部分是作为学习练习 - 请不要建议 I Style、DataTemplate、ControlTemplate 和 ListBox 等......即请不要质疑这种需要——只要假设它是真实的。
我浏览了网络,发现了很多有用的 ItemControl 信息,但没有明确的例子。
当我在 VS 中创建新的自定义控件时,我得到了实际上是空的代码和带有 <Style>
的 Generic.xaml可以通过 <Setter Property="Template">
设置 ControlTemplates、DataTemplates、Presenter 等的 block 等等。但是这里需要的最小 xaml/代码是多少才能获得一个控件,该控件将绑定(bind)到一个 ObservableCollection 到 ItemsSoruce 以显示为一个列表? 换句话说:ItemsControl 派生的自定义控件的规范形式是什么?
我需要 ItemsPresenter 吗?是否必须在 ControlTemplate 中指定堆栈面板?我是否必须在 <Setter Property="ItemTemplate">
上设置 TargetType? ?等等
勺子喂食更喜欢例如说:它很容易,我只需要在项目控制容器的向量空间上集成 DataTemplate 相对于面板演示者 yada yada ......不是一个很大的帮助。
更多信息:该控件仅面向显示,即没有选定项目等的概念。
提前致谢!
默认 Generic.xaml(这里最少要添加什么?):
<Style TargetType="{x:Type local:MyItemsControlDerivedClass}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyItemsControlDerivedClass}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
最佳答案
看看default styles (点击 Default WPF Themes
链接):
例如列表框:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true"
Padding="1">
<ScrollViewer Padding="{TemplateBinding Padding}"
Focusable="false">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled"
Value="false">
<Setter TargetName="Bd"
Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping"
Value="true">
<Setter Property="ScrollViewer.CanContentScroll"
Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
关于WPF ItemsControl 派生的自定义控件帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872968/
我正在使用 M-V-VM 并在我的 ViewModel 上有一个名为“EntitySelectedCommand”的命令。 我试图让 ItemsControl 中的所有项目来触发这个命令,但是它不起作
在我的 View 中有一个 ItemsControl,它绑定(bind)到来自 ViewModel 的 ObservableCollection。集合被填充,然后引发从 VM 到 View 的事件(想
我最近遇到了一个虚拟化问题,我将其缩小到以下代码。 虚拟化在以下代码段中不起作用的原因是因为 child 没有特定的高度。所以我的猜测是它会永远扩展并且虚拟化会中断。 给 child 一个特定的高度解
我是 WPF 的新手。我一直在尝试执行以下操作: 以下是我的数据结构: public class TokenItems {public string items {get;set;} public i
我正在尝试从 WPF MVVM 教程中扩展应用程序作为练习。对于我在这里面临的这个特定问题,我在网上没有找到解决方案。 我有一个名为“StudentsToAdd”的带有 ObservableColle
我正在使用带有 MVVM 模式的 Wpf,所以在 Xamel 中,我有一个 itemControl 持有另一个 itemcontrol,每个 itemcontrol 绑定(bind)来自不同的 Obs
标题可能听起来令人费解,但请耐心等待。 我有包含住户的房间: public class Room { public string Name { get; set; } public L
我需要能够从子 ItemsControll 数据模板内部绑定(bind)到父 ItemsControl 的属性:
这让我发疯。也许我的数据设计有误,但我正在尝试从父 ItemsControl 绑定(bind)到事件项目。 每个区域都有一种颜色,以便在屏幕上轻松识别。我没有为每个座位赋予颜色属性,而是在 Area
我的问题与此非常相似:( Binding events to buttons in an ItemsControl ) 但我没有在那里找到解决方案。我有一个 ItemsControl,在它的 Data
考虑以下 XAML
在我的主视图中,我有一个绑定(bind)到对象集合的 ItemsControl: ActivationLevelTemplate 只是另一个 View : 在这个 View 中有一
我正在使用 ItemsControl,其中 ItemsPanel 设置为 Canvas(有关更多背景信息,请参阅 this 问题)。ItemsControl 正在按我想要的方式执行,并且通过将子元素放
我有一个 ScrollViewer,里面有一个 ItemsControl。 ItemsControl 的 ItemSource 绑定(bind)到 ObservableCollection。 问题是它
我有一个带有 itemscontrol 的 WPF MVVM 应用程序。水平子项的数量受 itemscontrol 宽度的影响。只有一件事我没有解决。我试图以始终居中的方式对齐子元素。我已经用油漆制作
我有以下 XAML: 当我将数据拖到此面板上时,鼠标光标显示允许在所有子项上放置,但在任何空白区域上,光标显示禁止放置。如果我设置 AllowDro
我有一些数据要显示在 FlowDocument 中.这基本上是一个以友好方式解释数据的 View ,包括节标题、文本段落等,我将在 FlowDocumentScrollViewer 中显示这些 Vie
我有一个 ItemsControl包含我想虚拟化的数据列表,但是 VirtualizingStackPanel.IsVirtualizing="True"似乎不适用于 ItemsControl . 真
我想写一个 ItemsControl 派生的自定义控件。这部分是出于需要,部分是作为学习练习 - 请不要建议 I Style、DataTemplate、ControlTemplate 和 ListBo
我想使用ItemsControl显示重要的项目列表。 我使用ItemsControl的原因是,我正在处理的应用程序中的DataTemplate要复杂得多:提供的示例代码仅反射(reflect)了我的大
我是一名优秀的程序员,十分优秀!