MVVM 和 DevExpress

发布于 2024-10-03 00:24:13 字数 91 浏览 1 评论 0原文

我在我的项目中使用 devexpress 控制套件。其中一个控件(选项卡控件)要求我将控件而不是视图模型加载到选项卡中。做到这一点并且仍然正确分离信息的最佳方法是什么?

I am using the devexpress control suite in my project. One of there controls, the tab control, requires that I load the control not the viewmodel into the tabs. What would be the best way to do this and still seperate the information correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-10-10 00:24:13

Dan,我不知道你从哪里得到的信息,DevExpress 的 DXTabControl 不能以 MVVM 方式使用。请看一下下面的代码/XAML。


using System.Collections.Generic;
using System.Windows.Controls;

namespace SilverlightApplication91 {
    public partial class MainPage : UserControl {
        public MainPage() {
            InitializeComponent();
        }
    }

    public class ViewModel {
        public ViewModel() {
            Employees = new List<Person> {
                new Person { FirstName = "Larry", LastName = "Ellison" },
                new Person { FirstName = "Steve", LastName = "Jobs" },
                new Person { FirstName = "Bill", LastName = "Gates" }
            };
        }

        public List<Person> Employees { get; private set; }
    }

    public class Person {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
}

<Grid x:Name="LayoutRoot" Background="White">
    <core:DXTabControl ItemsSource="{Binding Employees}">
        <core:DXTabControl.ItemHeaderTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding FirstName}"/>
            </DataTemplate>
        </core:DXTabControl.ItemHeaderTemplate>
        <core:DXTabControl.ItemTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding LastName}"/>
            </DataTemplate>
        </core:DXTabControl.ItemTemplate>
    </core:DXTabControl>
</Grid>

Dan, I don't know where you got the information that DXTabControl from DevExpress cannot be used in the MVVM manner. Please take a look at the following code/XAML.


using System.Collections.Generic;
using System.Windows.Controls;

namespace SilverlightApplication91 {
    public partial class MainPage : UserControl {
        public MainPage() {
            InitializeComponent();
        }
    }

    public class ViewModel {
        public ViewModel() {
            Employees = new List<Person> {
                new Person { FirstName = "Larry", LastName = "Ellison" },
                new Person { FirstName = "Steve", LastName = "Jobs" },
                new Person { FirstName = "Bill", LastName = "Gates" }
            };
        }

        public List<Person> Employees { get; private set; }
    }

    public class Person {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
}

<Grid x:Name="LayoutRoot" Background="White">
    <core:DXTabControl ItemsSource="{Binding Employees}">
        <core:DXTabControl.ItemHeaderTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding FirstName}"/>
            </DataTemplate>
        </core:DXTabControl.ItemHeaderTemplate>
        <core:DXTabControl.ItemTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding LastName}"/>
            </DataTemplate>
        </core:DXTabControl.ItemTemplate>
    </core:DXTabControl>
</Grid>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文