上使用Caliburn.Micro绑定功能"内"用户控制 [英] Using Caliburn.Micro binding feature on an "inner" user control
问题描述
我是很新的Caliburn.Micro,所以我想这有一个简单的答案(或至少我希望它有:))
我有一个视图模型有一个名为属性 ConnectedSystem
,有一个子属性名为名称
。
在我看来,我有以下的XAML(节选):
< StackPanel的方向=横向>
<标签内容=姓名:/>
< TextBlock的X:名称=ConnectedSystem_Name/>
< / StackPanel的>
这工作得很好,并且名字显示在的TextBlock
预期。然而,ConnectedSystem有应显示大约10属性,我不想复制粘贴上述里面我认为10倍的XAML。相反,我想提取XAML作为一个用户控件在那里我可以设置LabelText和文本的属性。
我想这一点,但我不知道我怎么能得到Caliburn.Micro自动传递ConnectedSystem_Name到我的用户。
这可能是一个比使用用户控件在这里也更好的办法,所以这个问题基本上是:是什么把这个共享的XAML,因为它是自己控制的最好办法,仍然能够使用Caliburn.Micros结合。 P>
Caliburn.Micro不会自动连接多个项目,以一个单一的控制处理好。然而,你不必依靠自动粘结剂,可以使用普通的老WPF结合吧。
A 用户控件
是要走的路在这里。在code,可添加两个DependencyProperties, LabelText
和文本
。
然后在XAML为你的用户控件,绑定到新的属性。
如果您使用此控件,您现在可以设置LabelText和文本值在XAML。所以,在你的主视图添加控件,并绑定 LabelText
和文本
来在你的视图模型的属性。
I'm quite new to Caliburn.Micro, so I guess this has a simple answer (or at least I hope it has :))
I have a ViewModel with a property called ConnectedSystem
that has a sub-property called Name
.
In my View, I have the following XAML (excerpt):
<StackPanel Orientation="Horizontal">
<Label Content="Name:" />
<TextBlock x:Name="ConnectedSystem_Name" />
</StackPanel>
This works just fine, and the name is shown in the TextBlock
as expected. However, ConnectedSystem has around 10 properties that should be displayed, and I don't want to copy-paste the XAML above 10 times inside my view. Instead I want to extract that XAML as a UserControl where I can set the LabelText and Text as properties.
I tried this, but I'm not sure how I can get Caliburn.Micro to pass the ConnectedSystem_Name into my UserControl automatically.
It might be a better way than using a UserControl here also, so the question is basically: What is the best way of putting this shared XAML as it's own control, and still be able to use Caliburn.Micros binding.
Caliburn.Micro doesn't deal well with automatically linking multiple items to a single control. However you don't have to rely on the automatic binder, you can use a plain old wpf binding instead.
A UserControl
is the way to go here. In the code you can add two DependencyProperties, LabelText
and Text
.
Then in the XAML for your UserControl, bind to the new properties.
Where you use this control you can now set the LabelText and Text values in XAML. So on your main view add the control, and bind LabelText
and Text
to the properties in your ViewModel.
这篇关于上使用Caliburn.Micro绑定功能&QUOT;内&QUOT;用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!