我正在编写一个 WPF 应用程序,性能有点慢,所以我正在尝试解决它。当我跑步时,我会收到大量这些类型的消息:
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=(0); DataItem=null; target element is 'Control' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=ValidationErrorTemplate; DataItem=null; target element is 'Control' (Name=''); target property is 'Template' (type 'ControlTemplate')
如果我做一个小示例应用程序:
<Window x:Class="bindingerrors.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bindingerrors="clr-namespace:bindingerrors" Title="MainWindow">
<Window.Resources>
<bindingerrors:Thinger x:Key="Thing" />
</Window.Resources>
<StackPanel>
<DataGrid x:Name="TheGrid" ItemsSource="{Binding Stuff, Source={StaticResource Thing}}" AutoGenerateColumns="False" HeadersVisibility="Column">
<DataGrid.Columns>
<DataGridTextColumn Header="!" Binding="{Binding A, FallbackValue=''}" />
<DataGridTextColumn Header="#" Binding="{Binding I, FallbackValue=''}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</Window>
以及以下对象定义:
public class Thinger
{
public ObservableCollection<ARow> Stuff { get; private set; }
public Thinger()
{
//Fill up some bogus data
string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i = 0;
Stuff = new ObservableCollection<ARow>();
foreach (var letter in letters)
{
Stuff.Add(new ARow(letter.ToString(),i));
i++;
}
}
}
public class ARow
{
public string A { get; private set; }
public int I { get; set; }
public ARow(string a, int i)
{
A = a;
I = i;
}
}
执行后,我会遇到大量的绑定问题。因为许多 WPF 性能文章声称失败的绑定会严重影响性能,所以我怀疑这可能是我的许多问题的根源。
到底是怎么回事?如何消除这些失败的绑定?我提供的示例尽可能简单,同时仍然是问题的症状,但它应该可以正常工作,不是吗?我正在为 .net 4.0 构建,如果这有什么不同的话。
编辑:如果您尝试构建示例代码,可能会抑制错误。在 Visual Studio 选项 -> 调试 -> 输出窗口 -> 数据绑定中,看到它设置在“信息”上。
我在 WPF 输出窗口中看到了 Getting many Binding "Information",但没有关于如何处理它的信息。
谢谢