C# 使用列表和多视图模型属性时的MVVM视图表示
关于 我试图以此为基础,而不是简单地使用列表框中的文本,我希望能够插入一个UserControl,显示模型的3个不同属性,或者我需要另一个ViewModel吗 我可以很容易地将UserControl直接添加到ListBox中,但我很确定这与MVVM模式不一致 只是想知道是否有人能帮忙 用户控制代码 用户控制界面 在上一个示例中的ViewModel中,我们有这些集合,它们是作为ActionItem的集合还是需要ActionModule的集合C# 使用列表和多视图模型属性时的MVVM视图表示,c#,wpf,design-patterns,mvvm,C#,Wpf,Design Patterns,Mvvm,关于 我试图以此为基础,而不是简单地使用列表框中的文本,我希望能够插入一个UserControl,显示模型的3个不同属性,或者我需要另一个ViewModel吗 我可以很容易地将UserControl直接添加到ListBox中,但我很确定这与MVVM模式不一致 只是想知道是否有人能帮忙 用户控制代码 用户控制界面 在上一个示例中的ViewModel中,我们有这些集合,它们是作为ActionItem的集合还是需要ActionModule的集合 public class ActionsViewMode
public class ActionsViewModel : PropertyChangedBase
{
public ObservableCollection<ActionItem> AvailableActions { get; set; }
public ObservableCollection<ActionItem> SelectedActions { get; set; }
public ActionItem FocusedAction1 { get; set; }
public ActionItem FocusedAction2 { get; set; }
提前感谢您的帮助:您正在使用Caliburn.Micro吗?基于PropertyChangedBase,我想冒昧地猜测一下,但它可能是您自己的基类,所以我想确定……ActionItems的集合是好的,因为actionitem的属性将绑定到您的数据模板。但是列表框在哪里,包含数据绑定的代码在哪里?我猜甚至不需要用户控制,您可以在ListBox中立即使用datatemplate参考这篇msdn文章-谢谢,我目前正在处理这篇文章,以确认它符合我的需要,但到目前为止,它看起来很有希望:
<UserControl x:Class="DelegateAction.ActionModule"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" >
<DockPanel>
<DockPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Height" Value="24" />
<Setter Property="Padding" Value="3" />
</Style>
</DockPanel.Resources>
<TextBlock DockPanel.Dock="Top" MinWidth="150" Text="Title"/>
<Button DockPanel.Dock="Bottom" Content="Action" MinWidth="150" />
<TextBlock DockPanel.Dock="Left" MinWidth="75" Text="Owner"/>
<TextBlock DockPanel.Dock="Right" MinWidth="75" Text="Score" />
</DockPanel>
public class ActionItem
{
public string Title { get; set; }
public string Owner { get; set; }
public short Score { get; set; }
public Action Action { get; set; }
}
public class ActionsViewModel : PropertyChangedBase
{
public ObservableCollection<ActionItem> AvailableActions { get; set; }
public ObservableCollection<ActionItem> SelectedActions { get; set; }
public ActionItem FocusedAction1 { get; set; }
public ActionItem FocusedAction2 { get; set; }