Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding DataGridTextColumn Forground with converter will not pick up correct color #52

Closed
Depechie opened this issue Mar 14, 2016 · 6 comments
Labels

Comments

@Depechie
Copy link

#38 Was originally posted and said to be fixed.

Indeed now we can run the grid with forground binding, but it's still not picking up the correct color.
Cfr the example in #38 when the bool is True the foreground should be red, but we are not getting any red items in the grid.
Even though the value converter is returning color red.

@RicoSuter RicoSuter added the bug label Apr 4, 2016
@Depechie
Copy link
Author

Any changes on this?

@RicoSuter
Copy link
Owner

The color must be a brush, just use:

public class BoolToColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if (value != null && value is bool && (bool) value)
            return new SolidColorBrush(Colors.Red);

        return new SolidColorBrush(Colors.Black);
    }

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

@RicoSuter
Copy link
Owner

image

@RicoSuter
Copy link
Owner

Btw: Just check the VS Output window and you'll see the problem:

Error: Converter failed to convert value of type 'Windows.UI.Color' to type 'Brush'; BindingExpression: Path='IsPrio' DataItem='TestMyToolkitGrid.Models.Location'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Foreground' (type 'Brush'). 
Error: Converter failed to convert value of type 'Windows.UI.Color' to type 'Brush'; BindingExpression: Path='IsPrio' DataItem='TestMyToolkitGrid.Models.Location'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Foreground' (type 'Brush'). 
Error: Converter failed to convert value of type 'Windows.UI.Color' to type 'Brush'; BindingExpression: Path='IsPrio' DataItem='TestMyToolkitGrid.Models.Location'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Foreground' (type 'Brush'). 

@Depechie
Copy link
Author

Depechie commented Sep 2, 2016

Awesome, will try that! Hmm missed that VS output :/

@Depechie
Copy link
Author

Depechie commented Sep 3, 2016

Works like a charm

@Depechie Depechie closed this as completed Sep 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants