问题描述
大家好,
我正在通过MVVM架构转换我的WPF应用程序。我的应用程序中有一个xaml,它使用Property Grid并使用它显示数据。现在对于MVVM架构,我必须通过绑定来完成所有这些。我已经阅读了大约100多篇文章,但没有得到任何适当的例子来说明这个或者在MVVM架构中使用Property Grid。
请紧急帮我解决这个问题。我需要一个简短的演示,它使用MVVM架构并将数据绑定到Property Grid。
Hi All,
I am converting my WPF application over MVVM architecture. There is one xaml in my application which uses Property Grid and display data using it. Now for MVVM architecture i have to do all this through binding. I have gone through around 100+ articles but didn't get any appropriate example which shows this or which uses Property Grid in MVVM architecture.
Please urgently help me regarding this. I need a short demo which usse MVVM architecture and bind data to Property Grid.
推荐答案
<Window xmlns:my="clr-namespace:WpfPropertyGrid" x:Class="WpfPropertyGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<my:View />
</Grid>
</Window>
View.xaml:
The View.xaml:
<UserControl x:Class="WpfPropertyGrid.View"
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"
xmlns:xceedPg="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid;assembly=Xceed.Wpf.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<xceedPg:PropertyGrid SelectedObject="{Binding}"/>
</Grid>
</UserControl>
View.cs :
View.cs:
/// <summary>
/// Interaction logic for View.xaml
/// </summary>
public partial class View : UserControl
{
public View()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
}
ViewModel.cs:
ViewModel.cs:
public class ViewModel
{
public ViewModel()
{
FirstName = "Shai";
LastName = "Vashdi";
}
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Information")]
[DisplayName("Last Name")]
[Description("This property uses a TextBox as the default editor.")]
public string LastName { get; set; }
}
我希望它有所帮助:)
I Hope It helps :)
这篇关于MVVM体系结构中的属性网格绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!