如何在C#中实例化整个XAML网格? [英] How to instantiate an entire XAML grid in C#???
问题描述
我有一个复杂的GRID元素,描述了很多东西,比如物体变换,速度,质量等。 我希望能够在实例化对象时通过代码实例化此网格。 但是,我不确定如何将我在XAML中所做的
封装到C#中? 任何帮助?
您可以将所有内容放在用户控件中,然后只是实例化该用户控件。
或
您可以定义模板,将标记放入其中并将其与viewmodel关联使用datatype =。每当您将该视图模型(类型)的实例作为内容呈现给ui时,它将使用您的模板对其进行模板化。
或
您可以放置txt文件中的标记和进入ui控件的xamlreader.parse。或者是xamlreader.load创建网格的未编译.xaml文件。
取决于您的目的。
Hi, I have a complicated GRID element describing many things like an objects transform, velocity, mass, etc. I want to be able to instantiate this grid through code, when I instantiate an object. However, I'm unsure how to encapsulate what
I did in XAML into C#? Any help?
You could put everything in a usercontrol and then just instantiate that usercontrol.
Or
You could define a template, put your markup in that and associate that with a viewmodel use datatype=. Whenever you present an instance of that viewmodel ( type ) to the ui as content it will template it using your template.
Or
You could put the markup in a txt file and xamlreader.parse that into ui controls. Or an uncompiled .xaml file you xamlreader.load to create a grid.
Depends what your purpose is.
这篇关于如何在C#中实例化整个XAML网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!