Gosha
Topic Author
Posts: 8
Joined: 27 Jul 2021, 16:06

Binding Noesis::Color with VM

12 Aug 2021, 16:53

Hello!
I have a ColorPicker UserControl with Noesis::Color DependencyProperty.
NS_IMPLEMENT_REFLECTION(ColorPicker, "d.ColorPicker")
{
    Noesis::DependencyData* data = NsMeta<Noesis::DependencyData>(Noesis::TypeOf<SelfClass>());
    data->RegisterProperty<Noesis::Color>(CurrentColorProperty, "CurrentColor", Noesis::PropertyMetadata::Create(Noesis::Color{}));
}
I also have a ViewModel inherited from INotifyPropertyChanged. It has a Noesis::Color field that I "register" via NsProp. The getter returns const Noesis::Color&, since otherwise it gave me compilation errors.
const Noesis::Color& SomeVM::GetColor() const
{
    return _color;
}
void SomeVM::SetColor(const Noesis::Color& v)
{
    if (_color!= v)
    {
        _color= v;
        OnPropertyChanged("Color");
    }
}
NS_BEGIN_COLD_REGION
NS_IMPLEMENT_REFLECTION(SomeVM, "d.SomeVM")
{
    NsProp("Color", &SomeVM::GetColor, &SomeVM::SetColor);
}
NS_END_COLD_REGION
I want to bind CurrentColor DependencyProperty with the ViewModel field.
 <d:ColorPicker CurrentColor="{Binding SomeViewModel.Color, Mode=TwoWay}"/>
But when I try to bind, I get the error:
Unable to convert 'Binding SomeViewModel.Color, Mode=TwoWay}' to a valid value for property d.ColorPicker.CurrentColor.
What am I doing wrong? Perhaps the problem is that the getter returns a const Noesis::Color& and a converter is needed?
 
Gosha
Topic Author
Posts: 8
Joined: 27 Jul 2021, 16:06

Re: Binding Noesis::Color with VM

12 Aug 2021, 17:10

Sorry, guys.
Once I made a post, I found a problem that is beyond the scope of the question. :D
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: Binding Noesis::Color with VM

12 Aug 2021, 17:47

Great! Thanks for closing this :)

Who is online

Users browsing this forum: No registered users and 47 guests