English 中文(简体)
约束方式 C#中与XAML和WPF在MVVV 与环境中的观点
原标题:Howto bind Views to Viewmodel in a MVVM-Environment with XAML and WPF in C#

如果我想对我的看法加以约束,则在我的SAML-Code资源中增加以下内容:

<Window.Resources>
    <DataTemplate DataType="{x:Type MyViewModel}" >
        <views:MyView />
    </DataTemplate>
</Window.Resources> 

是否有可能在C#-Code增加我的资源词典(概览、概览)的资源输入?

The following two lines create the key and add it to the dictonary:

DataTemplateKey key = new DataTemplateKey(typeof(MyViewModel));
View.WindowName.Resources.Add(key, value);

But how can I create the value from the MyView which must have the type System.Windows.Baml2006.KeyRecord?

最佳回答

here 它是关于你如何制作带有c#代码的数据集的样本。

p.: 贵问题的标题应当像如何用c#代码制作一个数据模版。 这与mvm毫不相干。 更应该说,这部法典不应纳入“观点”。

编辑:

DataTemplate temp = new DataTemplate();
temp.DataType = typeof (MyViewModel);

FrameworkElementFactory fac = new FrameworkElementFactory(typeof(MyView));

temp.VisualTree = fac;

View.WindowName.Resources.Add(new DataTemplateKey(typeof(MyViewModel)), temp );

更容易地在Xaml :

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签