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

Compatibility with ReactiveUI bindings #370

Closed
grounch opened this issue Feb 6, 2021 · 3 comments
Closed

Compatibility with ReactiveUI bindings #370

grounch opened this issue Feb 6, 2021 · 3 comments
Labels
question Further information is requested

Comments

@grounch
Copy link

grounch commented Feb 6, 2021

Hi

Not sure if it's really a bug of your plugin or a conflict with reactiveui.

I'm implementing design for an existing xamarin app using reactiveui.
The problem is to handle bindings. When this way of binding was working before

Code behind of xaml

InitializeComponent();

this.WhenActivated(disposables =>
{
     this.Bind(ViewModel, vm => vm.knob, v => v.slidertest.SliderValue,
                    vmToViewConverter: v => (float)v, viewToVmConverter: v => (byte)v)
                    .DisposeWith(disposables);
}

it returns the error "Operation is not valid due to the current state of the object" once the slider is placed in a carouselview containing few ContentView

Capture d’écran 2021-02-06 à 18 07 20

Simplified xaml looks like that:

      <core:CarouselView >
           <x:Arguments>
               <proc:CarouselProcessor OpacityFactor="-0.5"/>
           </x:Arguments>

   	<core:CarouselView.ItemsSource>
   		<x:Array Type="{x:Type ContentView}">

   			<ContentView >
                                     <Label Text="nothing"/>
                               </ContentView>

                              <ContentView>

                              <core:SliderView x:Name="slidertest"
                                                           Padding="30,0"/>

                             </ContentView>
   		</x:Array>
		</core:CarouselView.ItemsSource>

           <controls:Indicators  SelectedIndicatorStyle="{StaticResource ActiveIndicator}"
                                 UnselectedIndicatorStyle="{StaticResource InactiveIndicator}"/>
           <controls:LeftArrow ImageSource="arrow_left_grey" WidthRequest="12" HeightRequest="20"/>
           <controls:RightArrow ImageSource="arrow_right_grey" WidthRequest="12" HeightRequest="20"/>

</core:CarouselView>

If i take out the SliderView from the CarouselView it works fine.
Doesn't come from my custom control as i tried with simple elements like labels and i get the same behavior.

Not being a big fan myself of all this reactiveui messy bindings and commands, but redesigning the whole app code isn't really an option.
Did you had any similar reported issues?
The issue probably comes from the late initialization of the contentviews, happening after the reactiveui bindings. So it tries to bind to a not existing yet "slidertest"
Is there a way in code behind to make them load earlier as workaround? Before this.WhenActivated for example

Thanks

@grounch
Copy link
Author

grounch commented Feb 7, 2021

I think it's definitely an init timing issue.
If i put this in the code behind:

InitializeComponent();

labeltestoutside.Text = "out"; //placed outside the carouselview
labeltestinside.Text = "in"; // placed inside

and put breakpoints on them, the first one will be a Xamarin.Forms.Label, but the second will still be null and make he app crash.

@AndreiMisiukevich AndreiMisiukevich added the question Further information is requested label Feb 8, 2021
@AndreiMisiukevich
Copy link
Owner

Hi, and thank you for the interest in this project.

Does it work fine with Xamarin.Forms CarouselView?
I am pretty sure this bug is not related to this project.
That's more like your app's issue.

I can propose you to add views from the code behind

@grounch
Copy link
Author

grounch commented Feb 10, 2021

Found same behavior with the original CarouselView, so yes it's not a bug of your project.

That's what i ended up doing, created different views with my elements instead of putting everything directly in the XAML of the CarouselView, then stored the views in an ObservableCollection & setting this collection as carousel.ItemsSource in code behind.
That way the reactui bindings are in each view's code behind and accessing the elements well.

@grounch grounch closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants