Skip to content

SelectedColor Binding Not Updateing ViewModel #51

@tpitman

Description

@tpitman

Describe the bug
When I try to bind the SelectedColor to a ViewModel class it gets the value, but won't set it

To Reproduce
Steps to reproduce the behavior:

  1. Create a project and get ColorPicker all set up according to instructions
  2. Add using Xamarin.Forms ViewModel binding by using the BindingContext in the xaml
  3. Add a property to the ViewModel of type Xamarin.Forms.Color with a get and set
  4. Add a ColorPicker to the xaml and use standard binding format to bind it to the view model property
  5. Run the project and change the color on the color wheel

Expected behavior
I would expect my view model property SET to be called any time the color changes.

Desktop (please complete the following information):

  • OS: iOS
  • Version: Latest

Additional context
If I change my xaml to be similar to the TestApp project so that another control in the xaml uses a reference binding then it work, but only if I remove my binding to my view model property. If they are both there, then neither one updates.

Note that when I have my view model binding in place and I set a break point in the GET of my property it does hit it and retrieves the color just fine.

Here is my xaml:

<StackLayout Orientation="Vertical" BackgroundColor="{Binding Source={x:Reference LabelColorWheel}, Path=SelectedColor}">
<colorpicker:ColorCircle x:Name="LabelColorWheel" SelectedColor="{Binding LabelColor}"/>
</StackLayout>

Here is my view model:

private Color _labelColor;
public Color LabelColor
{
get { return _labelColor; }
set
{
if (_labelColor != value)
{
_labelColor = value;
SafePropertyChanged("LabelColor");
}
}
}

I am sorry my formatting isn't very good. It doesn't seem to paste code like I expect.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions