unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.45k stars 685 forks source link

`x:Bind` to event does not work in `Window`-derived types #16520

Closed MartinZikmund closed 1 week ago

MartinZikmund commented 2 weeks ago

Current behavior

x:Bind to event does not work in Window-derived types, for repro see below

Expected behavior

Should work

How to reproduce it (as minimally and precisely as possible)

Create a TestWindow.xaml with the following content:

<?xml version="1.0" encoding="utf-8" ?>
<Window
    x:Class="WindowingSamples.TestWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:WindowingSamples.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

  <Grid>
      <Button Click="MaximizeClick" HorizontalAlignment="Stretch" Content="Maximize" />
  </Grid>
</Window>

And TestWindow.xaml.cs with the following:

<Button Click="{x:Bind Maximize}" HorizontalAlignment="Stretch" Content="Maximize" />

Workaround

using Microsoft.UI.Windowing;

namespace WindowingSamples;

public sealed partial class MinimizeMaximizeWindow : Window
{
    private OverlappedPresenter _presenter;

    public MinimizeMaximizeWindow()
    {
        InitializeComponent();

        _presenter = (OverlappedPresenter)AppWindow.Presenter;
    }

    public void Maximize(object sender, RoutedEventArgs args) => _presenter.Maximize();
}

Put a breakpoint on Maximize method. Notice clicking the button does not hit the breakpoint on Uno targets, while it does on WinUI.

Works on UWP/WinUI

Yes

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

No response

Affected platforms

WebAssembly, Android, iOS, Mac Catalyst, Skia (WPF), Skia (Linux X11), Skia (macOS), Skia (Linux Framebuffer), Skia (GTK), Windows (WinAppSDK)

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response