gpt4 book ai didi

c# - WPF 嵌套绑定(bind)令人头疼 : access outer ListView with nested ListView

转载 作者:行者123 更新时间:2023-11-30 16:10:56 25 4
gpt4 key购买 nike

我有这个:

<ListView ItemsSource="{Binding MyFirstCollection} >
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding DataContext.MyOtherCollection, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" >
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding}">

<!-- the error is in here somewhere -->
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource OrderExclusionConverter}">
<Binding Path="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type ListView}}}" />
<Binding Path="MemberCount.MemberCountID" />
</MultiBinding>
</CheckBox.IsChecked>

</CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView> </ListView>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

如果我在“错误在这里的某处”,我如何获得绑定(bind)以访问 MyFirstCollection 中的当前项目?

我试过这个:

Path="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type ListView}}}"

我认为这可行,但它给了我binding can only be set on a dependencyproperty of a dependencyobject 错误。

编辑:发布完整绑定(bind)

最佳答案

这个:

<Binding Path="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type ListView}}}" />

错了。您不能在另一个 BindingPath 属性上设置 {Binding}。你需要的是:

<Binding Path="DataContext" 
RelativeSource="{RelativeSource AncestorType=ListView, AncestorLevel=2}"/>

问题是您似乎混淆了属性语法属性元素语法。您可能想在 MSDN 上阅读有关这些概念的更多信息.

关于c# - WPF 嵌套绑定(bind)令人头疼 : access outer ListView with nested ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999653/

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