dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

MAUI needs easy way to call a method like with UWP's "x:Bind" #7713

Closed Qws closed 2 years ago

Qws commented 2 years ago

Description

I have to constantly write ICommand properties .. everything works, but after using UWP and WASDK for a while, I think writing Commands is honestly annoying and also doesn't make ViewModel readable and managable.

Public API Changes

MAUI/WPF/Silverlight version:

public ViewModel()
{
    SaveCommand = new Command(Save);
}

public ICommand SaveCommand;

public void Save()
{
    //Saving logic;
}

And now UWP version:

public void Save()
{
    //Saving logic
}

Look at the differences, this is just 1 ICommand... It makes viewmodels unnecessarily verbose the more commands you add.

Intended Use-Case

Both ways work, but obviously writing less code leads to cleaner ViewModels...

MAUI needs out of the box x:Bind support. I don't really mind the lack of web/Linux support, I much rather want the best (enhanced) C#/XAML multiplatform coding experience that just works on the platforms that's supported.

We really need to move on from 2006 XP/Vista/WPF/Silverlight era Bindings and commands...

xtuzy commented 2 years ago

Maybe use MvvmToolKit is a optional way https://github.com/CommunityToolkit/MVVM-Samples/blob/master/samples/MvvmSample.Core/ViewModels/Widgets/ValidationFormWidgetViewModel.cs

MagicAndre1981 commented 2 years ago

MAUI needs out of the box x:Bind support.

Use this library:

https://github.com/levitali/CompiledBindings

This library provides {x:Bind} Markup Extension for WPF, MAUI and Xamarin Forms. You can read about {x:Bind} Markup Extension for UWP here. The whole functionality of {x:Bind} for UWP and also many other features are supported.

At XAML compile time, {x:Bind} is converted into C# code.

jfversluis commented 2 years ago

Thanks for the suggestion! It seems that we have attempted something like this in the past, but it wasn't received very well. So I think, before we do anything of the sorts, we might probably be better of starting a discussion where we test the waters and see how people feel about it and explore different ways to solve this issue. Feel free to open a discussion with all the arguments you have for this and maybe tag some of the people in the linked thread to get it going.

In the meanwhile there are alternatives like suggested.

Thanks!