如何在WPF输出窗口中消除绑定“信息” - 无法使用绑定检索值 [英] How to eliminate Binding “Information” in WPF output window - cannot retrieve value using the binding

查看:142
本文介绍了如何在WPF输出窗口中消除绑定“信息” - 无法使用绑定检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个WPF应用程序,性能有点慢,所以我试图解决它。当我运行时,我大概收到这些类型的消息:

  System.Windows.Data信息:10:无法检索存在使用绑定的值,并且没有有效的后备值存在;使用默认代替。 BindingExpression:路径=(0); DataItem = null;目标元素为Control(Name =');目标属性为可见性(类型可见性)
System.Windows.Data信息:10:无法使用绑定检索值,并且不存在有效的后备值;使用默认代替。 BindingExpression:Path = AreRowDetailsFrozen; DataItem = null; target元素是'DataGridDetailsPresenter'(Name =''); target属性为SelectiveScrollingOrientation(键入SelectiveScrollingOrientation)
System.Windows.Data信息:10:无法使用绑定检索值,并且不存在有效的后备值;使用默认代替。 BindingExpression:Path = HeadersVisibility; DataItem = null; target元素是'DataGridRowHeader'(Name ='');目标属性为可见性(类型可见性)
System.Windows.Data信息:10:无法使用绑定检索值,并且不存在有效的后备值;使用默认代替。绑定表达式:Path = ValidationErrorTemplate; DataItem = null;目标元素为Control(Name =');目标属性是模板(类型'ControlTemplate')

如果我做一个例子应用程序: / p>

 < 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 =TheGridItemsSource ={Binding Stuff,Source = {StaticResource Thing}}AutoGenerateColumns =FalseHeadersVisibility =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>东西{get;私人集合

public Thinger()
{
//填写一些虚假数据
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;私人集合}
public int I {get;组;

public ARow(string a,int i)
{
A = a;
I = i;
}
}

执行时,我遇到了这些绑定问题的山峰。由于许多WPF性能文章声称失败的绑定可能会严重影响性能,我怀疑这可能是我的许多问题的根源。



发生了什么?如何消除这些失败的绑定?我提供的例子就像我可以做到的一样简单,同时仍然是问题的症状,但它应该只是工作,不应该吗?我正在构建.net 4.0,如果这有任何区别。



编辑:如果您尝试构建示例,则可能会抑制错误码。在可视化工作室选项 - >调试 - >输出窗口 - >数据绑定中,看到它设置在信息上。



我看到获取许多绑定信息在WPF输出窗口,但是没有关于它在那里做什么的信息。



谢谢

解决方案

有一些事情可以解决,以消除一些错误。


  1. Stuff 有一个私人设置器,所以你必须设置
    BindingMode OneWay

  2. A 有一个私人设置器,所以你必须设置
    BindingMode OneWay

  3. I 具有不是 int 的回退值

但是,这些都不符合您发布的错误,但只是一些观察


I am writing a WPF application, and performance is it is a bit slow, and so I am trying to solve it. When I run, I get roughly a gazillion of these types of messages:

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')

If I make a little example application:

<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>

And the following object definitions:

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;
    }
}

Upon execution, I get mountains of those binding problems. Because many WPF performance articles claim that failed bindings can seriously hurt performance, I suspect this may be the source of many of my problems.

What is going on? How can I eliminate these failed bindings? The example I provided is as simple as I could make it while still being symptomatic of the problem, but it should just work, shouldn't it? I'm building for .net 4.0, if that makes any difference.

edit: The errors may be suppressed if you try building the sample code. In visual studio options -> debugging -> output window -> databinding, see that it is set on "Information".

I have seen Getting many Binding "Information" in WPF output window, but there is no information on what to do about it in there.

Thanks

解决方案

Well there are a few things you can fix to eliminate some of those errors.

  1. Stuff has a private setter so you will have to set the BindingMode to OneWay
  2. A has a private setter so you will have to set the BindingMode to OneWay
  3. I has a fallback value that is not an int value

However none of these match the errors you posted, but just some observations

这篇关于如何在WPF输出窗口中消除绑定“信息” - 无法使用绑定检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆