【发布时间】:2023-03-23 09:52:01
【问题描述】:
我正在处理一些相当大的 WPF 项目,其中包含大量的类和 XAML 设计文件。
但有一件事让我抓狂:IntelliSense 绑定自动完成有时不会显示正确的值(主要是在我无法提供正确的DataType 并且没有使用任何烘焙的情况下,例如Page 内容类型)
因此实际的问题是:有没有办法强制 IntelliSense 使用某种类型的自动完成功能?
作为随机示例,以这个 XAML:
<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
DataType="{x:Type Accounting}">
<ListView ItemsSource="{Binding Payments}">
<ListView.View>
<GridView>
<!--
Auto completion still assumes the type is Accounting
and displays the properties of Accounting instead of
the required Payments.
-->
<GridViewColumn DisplayMemberBinding="{Binding Bank}"/>
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
这对于 C# 类:
public class Accounting
{
public List<Payment> Payments { get; set; }
}
public class Payment
{
public string Bank { get; set; }
}
【问题讨论】:
-
您可以使用
{Binding Path=(xmlNameSpace:TypeName.PropertyName)}的形式来强制类型并完成 PropertyName。 -
嗨 X39,这个问题有什么更新吗?如果 Bradley 的回复有助于解决您的问题。您可以考虑将其标记为答案。如果仍然存在,请在创建一个具有类似结构的简单 wpf 项目后检查是否存在相同的问题。
标签: c# wpf visual-studio xaml intellisense