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="clr-namespace:EveTrader.Wpf.Selectors;assembly=EveTrader.Wpf">