alexrainman / SegmentedControl

MIT License
86 stars 38 forks source link

SelectedSegment bindable property is OneWay by default #7

Closed johankson closed 7 years ago

johankson commented 7 years ago

Shouldn't the SelectedSegment bindable property be TwoWay by default? In order to make it work you need to specify your binding like this.

SelectedSegment="{Binding SelectedSegment, Mode=TwoWay}

If it's by design, it should be added to the documentation.

alexrainman commented 7 years ago

Why you need it to be TwoWay? I am adding two methods to change selected tab and tint color programatically. Also, there's a event handler you can subscribe to segmentedcontrol named ValueChanged, that method is called when SelectedSegment changes.

alexrainman commented 7 years ago

Actually SelectedSegment is TwoWay somehow because of this. When SelectedSegment changes, ValueChanged delegate gets called. Normally you subscribe to it to change the content.

johankson commented 7 years ago

The nuget version doesn't update a data bound property. It might be fixed in source. I needed it two way to update the property on the view model. (Classic mvvm style). Close the issue if you don't think it's a good idea. It's just how I use it.

alexrainman commented 7 years ago

You can make it TwoWay no matter if by default is OneWay and your ViewModel will be updated as any time a tab is selected, SelectedSegment property is updated and the setter will be called in the abstraction code, indeed you ViewModel :)

johankson commented 7 years ago

Just figured since it's an input control, two way would work out of the box without specifically setting it.(It does not unless you changed it since the 1.1 nuget package). Just my 2c. It's like making Entry one way. :)

The event handler will not do any good since that would force you to be a bad person and put code in your code behind and he MVVM-gods would be displeased. :)

Unless I'm totally missing your point. Which is also a very possible reality.

alexrainman commented 7 years ago

Yes you are missing my point. ValueChanged event is to update the content container when selected segment changes and you can set SelectedSegment binding in TwoWay mode as Its setter will trigger when a tab is clicked :)

erichedstrom commented 7 years ago

Just to add my two cents, having TwoWay mode called out in the Readme would be helpful. I didn't know there was such an option and thought the binding to my ViewModel was broken until I found this issue.

Regardless, thank you for sharing the SegmentControl! It's very helpful.

alexrainman commented 7 years ago

Sorry guys, the plugin seems to be abandoned but its not. I just have been busy with my full time job. Will take care of the issues as soon as i can. Thanks