Dirkster99 / ColorPickerLib

A WPF/MVVM implementation of a themeable color picker control.
MIT License
47 stars 13 forks source link

Interaction with Microsoft Community Toolkit MVVM Library #6

Closed markolbert closed 3 years ago

markolbert commented 3 years ago

Re-opening an earlier issue/question...

I am relatively new to WPF, and am using the pre-release Microsoft Community Toolkit MVVM library.

The issue I'm running into involves the UI not calling the property setters for what should be bound properties:

<cpkr:ColorPicker Grid.Column="1" Grid.Row="1"
                  HorizontalAlignment="Left"
                  SelectedColor="{Binding RouteColor}"/>

public Color RouteColor
{
    get => _routeColor;

    set
    {
        SetProperty( ref _routeColor, value );

        _appConfig.RouteColor = value;
    }
}

The RouteColor property is contained in an ObservableObject.

When I run the app and change the color the property setter is not called. Similarly, the getter isn't called, either, when the control initializes because the displayed/default color is not what I've assigned to RouteColor as an initial value.

The exact same problem -- the setters and getters not being called -- takes place with your companion NumericUpDown library, too.

I'm not sure where the difficulty is, but I did do a simple test using a simple string property bound to a TextBox, and its getter gets called when the TextBox's value is updated.

markolbert commented 3 years ago

Okay, I figured out the problems.

First, part of my code base is a general purpose library which uses System.Drawing.Color because it needs to support both console apps and Windows desktop apps. Because the ColorPickerLib uses System.Windows.Media.Color accessing my viewmodel property was throwing exceptions.

Second, I had a typo in the property binding for the numeric updown control.