gpt4 book ai didi

wpf - 与 ElementName 绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-12-04 12:56:01 24 4
gpt4 key购买 nike

这是 XAML:

<DataGrid Grid.Column="0"  AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Path=Columns}"
x:Name="ColumnsGrid" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding Path=Header}"
Header="{Binding ElementName=ColumnsGrid, Path=DataContext.Count, StringFormat=Columns ({0}), diag:PresentationTraceSources.TraceLevel=High}"/>
</DataGrid.Columns>
</DataGrid>

绑定(bind)返回错误:System.Windows.Data 错误:2:找不到目标元素的管理 FrameworkElement 或 FrameworkContentElement。

我想念什么?

更新:

这是答案:
http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx

What is happening here? The Columns collection is just a property in the Datagrid; this collection is not in the logical (or visual) tree, therefore the DataContext is not being inherited, which leads to there being nothing to bind to.



更新 2:
关于 DataGrid 警告的好文章: http://blogs.msdn.com/b/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx

最佳答案

绑定(bind) DataGridColumn对于 Header abd Visibility属性需要特殊处理...

看到这个...

Bind datagrid column visibility MVVM

关于wpf - 与 ElementName 绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7964387/

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