Question

I have a WPF Solution with 2 projects, the first one (ResourcesLibrary) contains common styles and common resources. The other is the WPF application.

I created a style for DataGridRows in the ResourcesLibrary generic.xaml file:

<Style x:Key="DGRowStyle" TargetType="{x:Type DataGridRow}">
    <Setter Property="ValidationErrorTemplate">
        <Setter.Value>
            <ControlTemplate>
                <Image Source="/Resources/stop.png"
                       ToolTip = "{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}},
                       Path=(Validation.Errors),
                       Converter={StaticResource errorConverter]}}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

I added the .cs converter files to the ResourcesLibrary project:

namespace ResourceLibrary
{
    public class ErrorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            var errors = value as ReadOnlyObservableCollection<ValidationError>; 
            if (errors == null) 
                return ""; 
            return errors.Count > 0 ? errors[0].ErrorContent : ""; 
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        }
    }
}

And added the reference and the static resource:

xmlns:my="clr-namespace:ResourceLibrary"

<!-- CONVERTERS -->
    <my:ErrorConverter x:Key="errorConverter" />

But at runtime when, in the main project, I use the DataGridRow style defined in the ResourcesLibrary I get this error:

{"Cannot find resource named 'errorConverter]'. Resource names are case sensitive."}

Do I need to have another project inside my solution for the converters I will use?

Was it helpful?

Solution

Thanks to @Clemens I removed the extra char ']' in the expression "={StaticResource errorConverter]}" and it all works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top