Coder Social home page Coder Social logo

Comments (10)

maxkatz6 avatar maxkatz6 commented on September 14, 2024 1

They share the same BindingContext/DataContext (QRCodeViewModel) theough.

Looks like DataContext isn't passed automatically.
But it's something that should be handled by this library.

A workaround to add (in QRCodeView.axaml.cs file):

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
    base.OnPropertyChanged(change);

    if (change.Property == DataContextProperty)
    {
        ProgressBarHost.Content!.BindingContext = change.NewValue;
        BarcodeViewHost.Content!.BindingContext = change.NewValue;
    }
}

I also added BarcodeViewHost x:Name on the BarcodeView control host.

from avaloniamauihybrid.

maxkatz6 avatar maxkatz6 commented on September 14, 2024

I don't know why it stops rendering the native control once binding is added, but I can say for sure that bindings aren't supported here.
It's actually pretty similar to #20 issue.

In Avalonia XAML, bindings and xName works well, since all the elements are AvaloniaObjects. The same goes with MAUI, it all works while all elements are known to MAUI framework.

But when we mix different frameworks, it gets more complicated. You can't apply Avalonia.Binding to Maui.Control, since it doesn't inherit AvaloniaObject.

Known workaround is to create a separated MAUI Page (or ContentView) and setup MAUI Bindings there. And in Avalonia XAML file only include this Page, without any extra bindings.
This way, you will have one MAUI XAML file with MAUI bindings, and another Avalonia XAML file that has first one as a content.

from avaloniamauihybrid.

maxkatz6 avatar maxkatz6 commented on September 14, 2024

And to be clear, while it's technically possible to add x:Name support for MAUI elements, I don't think we can support bindings on MAUI controls, without making adding MAUI as a first-class support to our XAML compiler.

from avaloniamauihybrid.

maxkatz6 avatar maxkatz6 commented on September 14, 2024

Ideally, ZXing.Net.Maui should be re-ported to Avalonia using NativeControlHost, avoiding any other frameworks in between.
Hard to tell, how difficult it would be though. Technically, only camera view (a native control) needs to be wrapped into a NativeControlHost.

from avaloniamauihybrid.

gentledepp avatar gentledepp commented on September 14, 2024

yeah.. I aggree...

Regarding the preview overlapping everything else:
This seems to be a zxing.maui issue: If I run their demo project and try to put the camera preview into the middle row, it still overlaps.
Redth/ZXing.Net.Maui#4

The difference is, that AvaloniaMauiHybrid always renders all MAUI controls on top of everything else.
So I cannot render any avalonia controls on top of MAUI, correct?
Or is that a bug?

from avaloniamauihybrid.

maxkatz6 avatar maxkatz6 commented on September 14, 2024

On overlapping issue - the same would be with Avalonia-only port. Since native controls would be rendered on top of any avalonia content.

So I cannot render any avalonia controls on top of MAUI, correct?

So, yes. That's correct.
We have plans to support Popup (and Popup-related controls, like tooltip or flyout) to work on a separated layer though. It's already done on desktop (where it often is a separated window).

from avaloniamauihybrid.

gentledepp avatar gentledepp commented on September 14, 2024

Ok... makes sense.
Now, I updated the sample, so that the MAUI controls are in a separate MAUI View.
They share the same BindingContext/DataContext (QRCodeViewModel) theough.

But: Again the bindings do not have any effect on the MAUI controls.
Any thoughts?

from avaloniamauihybrid.

gentledepp avatar gentledepp commented on September 14, 2024

Apologies... I could have come to that conclusion myself... 😕
Thank you so much for all your valuable responses!

from avaloniamauihybrid.

gentledepp avatar gentledepp commented on September 14, 2024

Sorry - me again.
Now I tried out using ReactiveUI within MAUI controls.

For this, I started from the functioning prototype, where the MAUI UI parts are split out into their own views, so the MAUI bindings will work.
Everything works fine.

Now, i changed the ContentViews to become ReactiveContentView<>s and wanted to check if WhenActivated() was ever called.
It turns out, that, again, the UI simply isn't rendered anymore.

You can check out the branch here: https://github.com/gentledepp/POC_AvaloniaMauiApp01/tree/poc/settingmauipropsincodebehind

So is this now a bug or again some known shortcoming?

from avaloniamauihybrid.

gentledepp avatar gentledepp commented on September 14, 2024

Additionally this POC has two demo viewmodels:
PicturesViewModel and QRCodeViewModel.
To "navigate" between them, the MainViewModel contains a ContentControl and a command that just swaps the CurrentViewModel
image

Interestingly, navigating from the QRCodeView to the PicturesView causes the PicturesView to (again) not be rendered at all:

truncation

Note: This also "works" when

  • starting out with the QRCodeViewModel
  • or re-using the viewmodel instances

from avaloniamauihybrid.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.