You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have an WinUI 3 app recently enabled native AOT but found that command binding stopped working only in the WebView2 control. Consider the following code:
public class MainWindowViewModel
{
public ICommand ButtonCommand => new RelayCommand<RoutedEventArgs>(OnButtonClicked);
public ICommand InitializeCommand => new RelayCommand<CoreWebView2InitializedEventArgs>(OnInitialized);
private void OnInitialized(CoreWebView2InitializedEventArgs? args)
{
MessageBox(0, $"WebView2 Initialized", "", 0);
}
private void OnButtonClicked(RoutedEventArgs? e)
{
MessageBox(0, $"Button Clicked", "", 0);
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(nint hWnd, string text, string caption, int options);
}
// Here's the RelayCommand
public class RelayCommand<T> : ICommand
{
private readonly Action<T?> ExecuteFunc;
private readonly Predicate<T?>? CanExecuteFunc;
public event EventHandler? CanExecuteChanged;
public RelayCommand(Action<T?> execute)
{
ArgumentNullException.ThrowIfNull(execute);
ExecuteFunc = execute;
}
public RelayCommand(Action<T?> execute, Predicate<T?> canExecute)
{
ExecuteFunc = execute;
CanExecuteFunc = canExecute;
}
public bool CanExecute(object? parameter)
{
T? param = (T?)Convert.ChangeType(parameter, typeof(T), CultureInfo.InvariantCulture);
return CanExecuteFunc is null || CanExecuteFunc(param);
}
public void Execute(object? parameter)
{
MainWindowViewModel.MessageBox(0, $"Execute called", "", 0);
T? param = (T?)Convert.ChangeType(parameter, typeof(T), CultureInfo.InvariantCulture);
ExecuteFunc(param);
}
}
There is a button and a WebView2 control in the above app. When directly running the code from VisualStudio, the app behaves as expected: a message box shows when Webview2 initializes and another one when button is clicked. However, when the app is published, only the command bound with the button works. Nothing happens when WebView2 initializes. Also tried a few other events such as WebView2.WebMessageReceived/NavigationCompleted, but it looks like none works after app is published. Other WinUI 3 controls seem to work as expected (Tried Button.Click, StackPanel.Load in the above XAML).
Does anyone know if anything in WebView2 SDK is trimmed off? or is there any known incompatibility with WebView2 + Microsoft.Xaml.Interactivity?
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
WinUI3/WinAppSDK
Operating System
Windows 11
OS Version
No response
Repro steps
Create an empty WinUI 3 app with Visual Studio.
Check "Publish native AOT", or ensure there is <PublishAot>true</PublishAot> in the app's csproj.
Copy the above XAML content into the MainWindow.xaml (but please note to change the class name).
Copy MainWindowViewModel and RelayCommand classes into MainWindow.xaml.cs.
Run the app, you should see a message box pops up when WebView2 loads, and another one shows when the button is clicked.
Publish a sideload package of the app and install it.
When the published app runs, there is no message box when WebView2 loads, but when the button is clicked, message box shows as expected.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered:
What happened?
Hi, I have an WinUI 3 app recently enabled native AOT but found that command binding stopped working only in the WebView2 control. Consider the following code:
There is a button and a WebView2 control in the above app. When directly running the code from VisualStudio, the app behaves as expected: a message box shows when Webview2 initializes and another one when button is clicked. However, when the app is published, only the command bound with the button works. Nothing happens when WebView2 initializes. Also tried a few other events such as WebView2.WebMessageReceived/NavigationCompleted, but it looks like none works after app is published. Other WinUI 3 controls seem to work as expected (Tried Button.Click, StackPanel.Load in the above XAML).
Does anyone know if anything in WebView2 SDK is trimmed off? or is there any known incompatibility with WebView2 + Microsoft.Xaml.Interactivity?
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
WinUI3/WinAppSDK
Operating System
Windows 11
OS Version
No response
Repro steps
<PublishAot>true</PublishAot>
in the app's csproj.Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: