开发者

Wpf Resource: "Unknown Build Error, 'Path cannot be null..."

The following is a snippet from a xaml defining a DataGrid in a Control, defining a template selector.

<DataGrid.Resources>
    <selector:CurrencyColorSelector x:Key="currencyColorSelector">
        <selector:CurrencyColorSelector.NegativeTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Balance, StringFormat=n}" Background="Red"/>
            </DataTemplate>
        </selector:CurrencyColorSelector.NegativeTemplate>
        <selector:CurrencyColorSelector.NormalTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Balance, StringFormat=n}"/>
            </DataTemplate>
        </selector:CurrencyColorSelector.NormalTemplate>
    </selector:CurrencyColorSelector>
</DataGrid.Resources>

Now, an error is thrown: "Unknown build error, 'Path cannot be null. Parameter name: path Line 27 Position 79.'" (Compiler or xaml validation error).

Edit

After a reboot of Visual Studio 2010 I get the following:

The tag 'CurrencyColorSelector' does not exist in XML namespace 'clr-namespace:EveTrader.Wpf.Selectors;assembly=EveTrader.Wpf'. Line 27 Position 18.

Which makes it even weirder, as I even have intelisense for the class.


I have no idea where this Path comes from, neither does my example show anything of it. If you doubleclick the error, it points to the end of <selector:CurrencyColorSelector x:Key="currencyColorSelector"> (line 27).

Did anybody encounter such a problem and has a solution for it? The example was from here: http://www.wpftutorial.net/DataGrid.html (Row Details depending on the type of data)

Clarification

This is under .net 4.0. The Problem has to do with the CurrencyColorSelector, as the Templates themselves work fine if used in the DataGridTemplateColumn on their own. CurrencyColorSelector derives from DataTemplateSelector.

CurrencyColorSelector

namespace EveTrader.Wpf.Selectors
{
    public class CurrencyColorSelector : DataTemplateSelector
    {
        public DataTemplate NegativeTemplate { get; set; }
        public DataTemplate NormalTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var data = item as DisplayWallets;

            if (data == null)
                return base.SelectTemplate(item, container);

            if (data.Balance < 0m)
                return NegativeTemplate;
            return NormalTemplate;
        }
    }
}

DisplayWallets

public class DisplayWallets
{
    public string Name { get; set; }
    public decimal Balance { get; set; }
}

Xaml selector definition

<UserControl x:Class="EveTrader.Wpf.WalletsView"
             xmlns:selector="开发者_如何学JAVAclr-namespace:EveTrader.Wpf.Selectors;assembly=EveTrader.Wpf">


Okay, I fixed it. The problem was the definition of selector:

xmlns:selector="clr-namespace:EveTrader.Wpf.Selectors;assembly=EveTrader.Wpf".

As the type CurrencyColorSelector resides in the EveTrader.Wpf assembly, this definition created a circular reference which created the error - the compiler tried to compile the assembly EveTrader.Wpf, but because of the defition of selector, it tried to create EveTrader.Wpf first. This continued ad nauseam. The fix is simple: remove the assembly definition: xmlns:selector="clr-namespace:EveTrader.Wpf.Selectors".

I fixed this problem after some hours of sleep after working through the night, which proves again, sleep is needed. Thanks for the help Igor anyway.


Path in Binding is usually the bit that follows the word Binding.

{Binding MyCustomText}
          ^
          |
        Binding

<!--OR-->

{Binding Path=MyCustomText}
               ^
               |
             Binding

This error means there is something wrong with the binding.

StringFormat Binding property was introduced in a service pack to .NET 3.5 from memory. A good way to check if your version of WPF supports StringFormat is to see if class BindingBase has a property StringFormat.

With updated informatin I got nothing :( Looks like it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜