gpt4 book ai didi

c# - Caliburn.Micro - 数据绑定(bind) contentpresenter 到 viewmodel

转载 作者:行者123 更新时间:2023-12-03 10:55:11 25 4
gpt4 key购买 nike

我在 caliburn micro 中遇到了一些数据绑定(bind) View 模型的问题,我有以下代码:

<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 是一个 View 模型,虽然数据绑定(bind)到简单的 ContentControl 使用 caliburn micros 命名约定来查找 View ,但在使用模板和 contentpresenter 时, View 模型绑定(bind)只是显示 View 模型的字符串表示,而不是寻找 View 。我不是这种事情的专家,我在谷歌上找不到答案。

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

最佳答案

而不是绑定(bind)到 Content属性,使用 cal:View.Model="{Binding ViewModelName}"反而。

例子:

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

关于c# - Caliburn.Micro - 数据绑定(bind) contentpresenter 到 viewmodel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22783383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com