【问题标题】:Caliburn.Micro - Databinding contentpresenter to viewmodelCaliburn.Micro - 数据绑定 contentpresenter 到 viewmodel
【发布时间】:2014-05-12 01:54:21
【问题描述】:

我在 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>

问题是,PaymentDetails 是一个视图模型,虽然数据绑定到简单的 ContentControl 使用 caliburn micros 命名约定来查找视图,但在使用模板和 contentpresenter 时,视图模型绑定只是显示视图模型的字符串表示,而不是寻找视图。我不是这方面的专家,我在谷歌上找不到答案。

我想要的是在使用模板时,让 viewmodel 绑定像往常一样自动找到视图,但我认为我在这里缺少一些理解。

【问题讨论】:

    标签: c# wpf mvvm caliburn.micro


    【解决方案1】:

    不要绑定到Content 属性,而是使用cal:View.Model="{Binding ViewModelName}"

    例子:

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

    【讨论】:

      猜你喜欢
      • 2011-05-01
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多