WPF中的动态控件创建 [英] Dynamic control creation in WPF

查看:289
本文介绍了WPF中的动态控件创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目,我有一些分层数据,我想通过一个花哨的WPF控件编辑。



数据结构基本上是一个表达式树。每个节点可以是不同的Expression类型,但是从相同的基类继承。这些不同的类型需要有自己的编辑方式。



我的想法是,我将使用WPF TreeView控件,然后为每种类型的表达式动态添加编辑器控件。我只对WPF的数据绑定和MVVM模式有一个基本的了解,所以我不知道这是否可行,甚至在哪里开始。任何指针或指导将不胜感激。

解决方案

听起来你正在寻找的是 HierarchicalDataTemplate类


I'm working on a project where I have some hierarchical data that I want to be able edit through a fancy WPF control.

The data structure is essentially an expression tree. Each node can be a different Expression type but inheriting from the same base class. These different types need to have their own way of editing them.

My thoughts are that I would use the WPF TreeView control and then dynamically add editor controls for each type of Expression. I have only a basic understanding of WPF's data binding and the MVVM pattern so I'm not sure if this is possible to do or even where to begin. Any pointers or guidance would be greatly appreciated.

解决方案

It sounds like what you're looking for is the HierarchicalDataTemplate class.

这篇关于WPF中的动态控件创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆