简体   繁体   English

Caliburn.Micro-将数据表示者绑定到ViewModel

[英]Caliburn.Micro - Databinding contentpresenter to viewmodel

I'm having some issues databinding viewmodels in caliburn micro, i have the follwoing code: 我在caliburn micro中将数据绑定到视图模型时遇到一些问题,我有以下代码:

<ContentControl Content="{Binding PaymentDetails}">
                <ContentControl.Template>
                    <ControlTemplate TargetType="ContentControl">
                        <Grid>
                            <Controls:RoundedBox/>
                            <ContentPresenter Content="{Binding PaymentDetails}" Margin="10,0,10,0"/>
                        </Grid>
                    </ControlTemplate>
                </ContentControl.Template>
            </ContentControl>

The problem is, that PaymentDetails is a viewmodel, and while databinding to a simple ContentControl works using caliburn micros naming convention to find the view, when using the template, and contentpresenter, the viewmodel binding simply displays the string representation of the viewmodel, rather than finding the view. 问题在于,PaymentDetails是一个视图模型,虽然使用caliburn micros命名约定将数据绑定到一个简单的ContentControl可以找到视图,但是使用模板和contentpresenter时,该视图模型绑定只是显示该视图模型的字符串表示形式,而不是查找视图。 I'm not an expert in this kind of thing, and i've failed to find the answer on google. 我不是这种事情的专家,而且我在Google上找不到答案。

What i want is while using the template, to have the viewmodel binding automatically find the view like usual, but i think i'm missing some understanding here. 我想要的是在使用模板时,让viewmodel绑定像往常一样自动找到视图,但是我想我在这里缺少一些了解。

Instead of Binding to the Content property, use cal:View.Model="{Binding ViewModelName}" instead. 代替绑定到Content属性,请使用cal:View.Model="{Binding ViewModelName}"

Example: 例:

<ContentControl cal:View.Model="{Binding PaymentDetails}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM