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

Announcing: WinUI 3 in Windows App SDK 1.1 Preview 3 ✨ #7061

Closed
gabbybilka opened this issue May 5, 2022 · 8 comments
Closed

Announcing: WinUI 3 in Windows App SDK 1.1 Preview 3 ✨ #7061

gabbybilka opened this issue May 5, 2022 · 8 comments
Labels
announcement discussion General discussion

Comments

@gabbybilka
Copy link
Member

gabbybilka commented May 5, 2022

1.1 Preview 3 Release of Windows App SDK

Earlier this week we released our third preview of the 1.1 release of the Windows App SDK! This preview includes new features and bug fixes for WinUI 3 apps, including:

  • Mica and Background Acrylic ✨
  • New extension categories in MSIX
  • Several bug fixes in the Notifications area

To see everything that's new and changed, see the full release notes here.

What's next

To keep up with progress being made on the Windows App SDK, please see our feature roadmap, which gets updated regularly.

Providing feedback

As we introduce new & upcoming features in our preview releases, we appreciate all of your feedback as we work towards a stable release:

  • For WinUI 3 feedback, please open an issue here, on the WinUI repo.
  • For feedback regarding all other Windows App SDK components, please open an issue on the Windows App SDK repo.
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label May 5, 2022
@gabbybilka gabbybilka pinned this issue May 5, 2022
@michael-hawker
Copy link
Collaborator

Just hit an Access Violation with ProtectedCursor, will update to this version and try again to see, currently on 1.0.1

@michael-hawker
Copy link
Collaborator

Yup still hitting issue with the latest, details here: #7062

FYI @gabbybilka @ryandemopoulos.

@JamasChuang94
Copy link

Why I use Nuget package to update WindowsAppSDK to 1.1.0 preview version 3 still can't use Background Acrylic in C++ desktop development

@michael-hawker
Copy link
Collaborator

Seeing an issue in our CI with the 1.1.0-preview3 package (that I didn't see with 1.0.0, testing 1.0.3 now):

Copying file "D:\a\Labs-Windows\Labs-Windows\labs\CiTestExp\tests\CiTestExp.UnitTests.WinAppSdk\bin\x64\Release\net6.0-windows10.0.19041.0\AppxManifest.xml" to layout "AppxManifest.xml"...
Checking whether required frameworks are installed...
Framework: Microsoft.WindowsAppRuntime.1.1-preview3/X86. Skipping installation because framework package architecture does not match target architecture X64 and app package architecture X64.
Framework: Microsoft.WindowsAppRuntime.1.1-preview3/X86. Skipping installation because framework package architecture does not match target architecture X64 and app package architecture X64.
Framework: Microsoft.WindowsAppRuntime.1.1-preview3/X64, app package version 1000.485.2229.0 is not currently installed.
Framework: Microsoft.WindowsAppRuntime.1.1-preview3/ARM64. Skipping installation because framework package architecture does not match target architecture X64 and app package architecture X64.
Installing missing frameworks...
DEP0800: The required framework "C:\Users\runneradmin\.nuget\packages\microsoft.windowsappsdk\1.1.0-preview3\buildTransitive\..\tools\MSIX\win10-x64\Microsoft.WindowsAppRuntime.1.1-preview3.msix" failed to install. [0x80073CF9] Deployment Add operation with target volume C: on Package Microsoft.WindowsAppRuntime.1.1-preview3_1000.485.2229.0_x64__8wekyb3d8bbwe from:  (Microsoft.WindowsAppRuntime.1.1-preview3.msix)  failed with error 0x8000000B. See http://go.microsoft.com/fwlink/?LinkId=235160 for help diagnosing app deployment issues.
	DeploymentSucceeded = False
	DeploymentError = Err_Deploy_SDKInstall
	DeploymentUserError = False
	DeploymentHRESULT = 2147958009
	HasSharedCode = False
	SDKFileName = 
Deleting file "vs.appxrecipe" from layout...
DeployAsync: END (Failure, 0:00:00.402)

Is this because it's a preview package or an issue that's regressed?

@ojhad ojhad added discussion General discussion and removed needs-triage Issue needs to be triaged by the area owners labels May 10, 2022
@WelterDevelopment
Copy link

WelterDevelopment commented May 12, 2022

How do I actually use Mica? The property "BackdropMaterial.ApplyToRootOrPageBackground" does still not exist in WinAppSDK 1.1 prev3
EDIT: OK, I found it! There is no documentation but a pull request for the WinUI-Gallery: microsoft/WinUI-Gallery@d9bfb9f

I want to change the theme at runtime, so I came up with the following adjustment:

SystemBackdropWindow.cs
using Microsoft.UI;
using Microsoft.UI.Composition;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml;
using System.Runtime.InteropServices;
using WinRT;

namespace YOURNAMESPACEGOESHERE
{
  public class SystemBackdropWindow : Window
  {
    public ApplicationTheme ActualTheme = ApplicationTheme.Dark;
    ElementTheme requestedTheme = ElementTheme.Default;
    public ElementTheme RequestedTheme
    {
	    get => requestedTheme;
	    set
	    {
		    requestedTheme = value;
    
		    switch (value)
		    {
			    case ElementTheme.Dark: ActualTheme = ApplicationTheme.Dark; break;
			    case ElementTheme.Light: ActualTheme = ApplicationTheme.Light; break;
			    case ElementTheme.Default:
				    var uiSettings = new Windows.UI.ViewManagement.UISettings();
				    var defaultthemecolor = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
				    ActualTheme = defaultthemecolor == Colors.Black ? ApplicationTheme.Dark : ApplicationTheme.Light;
				    break;
		    }
	    }
    }
    
    public SystemBackdropWindow()
    {
	    RequestedTheme = App.Current.RequestedTheme == ApplicationTheme.Dark ? ElementTheme.Dark : ElementTheme.Light;
    
	    m_wsdqHelper = new WindowsSystemDispatcherQueueHelper();
	    m_wsdqHelper.EnsureWindowsSystemDispatcherQueueController();
    
	    SetBackdrop(BackdropType.Mica);
    }
    
    public enum BackdropType
    {
	    Mica,
	    DesktopAcrylic,
	    DefaultColor,
    }
    
    WindowsSystemDispatcherQueueHelper m_wsdqHelper;
    BackdropType m_currentBackdrop;
    MicaController m_micaController;
    DesktopAcrylicController m_acrylicController;
    SystemBackdropConfiguration m_configurationSource;
    
    public void SetBackdrop(BackdropType type)
    {
	    m_currentBackdrop = BackdropType.DefaultColor;
	    if (m_micaController != null)
	    {
		    m_micaController.Dispose();
		    m_micaController = null;
	    }
	    if (m_acrylicController != null)
	    {
		    m_acrylicController.Dispose();
		    m_acrylicController = null;
	    }
	    this.Activated -= Window_Activated;
	    this.Closed -= Window_Closed;
	    m_configurationSource = null;
    
	    if (type == BackdropType.Mica)
	    {
		    if (TrySetMicaBackdrop())
		    {
			    m_currentBackdrop = type;
		    }
		    else
		    {
			    type = BackdropType.DesktopAcrylic;
		    }
	    }
	    if (type == BackdropType.DesktopAcrylic)
	    {
		    if (TrySetAcrylicBackdrop())
		    {
			    m_currentBackdrop = type;
		    }
		    else
		    {
		    }
	    }
    }
    
    bool TrySetMicaBackdrop()
    {
	    if (MicaController.IsSupported())
	    {
		    m_configurationSource = new SystemBackdropConfiguration();
		    this.Activated += Window_Activated;
		    this.Closed += Window_Closed;
    
		    m_configurationSource.IsInputActive = true;
		    switch (RequestedTheme)
		    {
			    case ElementTheme.Dark: m_configurationSource.Theme = SystemBackdropTheme.Dark; break;
			    case ElementTheme.Light: m_configurationSource.Theme = SystemBackdropTheme.Light; break;
			    case ElementTheme.Default: m_configurationSource.Theme = SystemBackdropTheme.Default; break;
		    }
    
		    m_micaController = new MicaController();
		    m_micaController.AddSystemBackdropTarget(this.As<ICompositionSupportsSystemBackdrop>());
		    m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
		    return true;
	    }
    
	    return false;
    }
    
    bool TrySetAcrylicBackdrop()
    {
	    if (DesktopAcrylicController.IsSupported())
	    {
		    m_configurationSource = new SystemBackdropConfiguration();
		    this.Activated += Window_Activated;
		    this.Closed += Window_Closed;
    
		    m_configurationSource.IsInputActive = true;
		    switch (RequestedTheme)
		    {
			    case ElementTheme.Dark: m_configurationSource.Theme = SystemBackdropTheme.Dark; break;
			    case ElementTheme.Light: m_configurationSource.Theme = SystemBackdropTheme.Light; break;
			    case ElementTheme.Default: m_configurationSource.Theme = SystemBackdropTheme.Default; break;
		    }
    
		    m_acrylicController = new DesktopAcrylicController();
    
		    m_acrylicController.AddSystemBackdropTarget(this.As<ICompositionSupportsSystemBackdrop>());
		    m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
		    return true;
	    }
    
	    return false;
    }
    
    private void Window_Activated(object sender, WindowActivatedEventArgs args)
    {
	    m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
    }
    
    private void Window_Closed(object sender, WindowEventArgs args)
    {
	    if (m_micaController != null)
	    {
		    m_micaController.Dispose();
		    m_micaController = null;
	    }
	    if (m_acrylicController != null)
	    {
		    m_acrylicController.Dispose();
		    m_acrylicController = null;
	    }
	    this.Activated -= Window_Activated;
	    m_configurationSource = null;
    }
  }
  
  class WindowsSystemDispatcherQueueHelper
  {
    [StructLayout(LayoutKind.Sequential)]
    struct DispatcherQueueOptions
    {
	    internal int dwSize;
	    internal int threadType;
	    internal int apartmentType;
    }
    
    [DllImport("CoreMessaging.dll")]
    private static extern int CreateDispatcherQueueController([In] DispatcherQueueOptions options, [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object dispatcherQueueController);
    
    object m_dispatcherQueueController = null;
    public void EnsureWindowsSystemDispatcherQueueController()
    {
	    if (Windows.System.DispatcherQueue.GetForCurrentThread() != null)
	    {
		    return;
	    }
    
	    if (m_dispatcherQueueController == null)
	    {
		    DispatcherQueueOptions options;
		    options.dwSize = Marshal.SizeOf(typeof(DispatcherQueueOptions));
		    options.threadType = 2;
		    options.apartmentType = 2;
    
		    CreateDispatcherQueueController(options, ref m_dispatcherQueueController);
	    }
    }
  }
}
MainPage.xaml.cs
public sealed partial class MainPage : Page
{
  ViewModel VM = App.VM;
  
  public MainPage()
  {
	  this.InitializeComponent();
  }
  
  private void Cbx_Theme_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
	  // Update your SystemBackdropWindow to use the new Theme (here, Cbx_Theme.SelectedItem is bound to ViewModel.RequestedTheme):
	  App.MainWindow.RequestedTheme = VM.RequestedTheme;
	  App.MainWindow.SetBackdrop(VM.RequestedBackdrop);
  
	  // Your TitleBarCustomization stuff goes here:
	  if (App.IsWin11)
	  {
		  App.AppWindow.TitleBar.ButtonForegroundColor = App.MainWindow.ActualTheme == ApplicationTheme.Dark ? Colors.White : Colors.Black;
	  }
  }
  
  private void Cbx_Backdrop_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
	  // Update your SystemBackdropWindow to use the new Backdrop (here, Cbx_Backdrop.SelectedItem is bound to ViewModel.RequestedBackdrop):
	  App.MainWindow.SetBackdrop(VM.RequestedBackdrop);
  }
}

But all of this is so complicated! Will there ever be a "BackdropMaterial.ApplyToRootOrPageBackground" implementation in WinAppSDK for Desktop?

@JamasChuang94
Copy link

我如何实际使用云母?WinAppSDK 1.1 prev3 中仍然不存在“BackdropMaterial.ApplyToRootOrPageBackground”属性 编辑:好的,我找到了!没有文档,但对 WinUI-Gallery 的拉取请求:microsoft/WinUI-Gallery@ d9bfb9f

我想在运行时更改主题,所以我想出了以下调整:

SystemBackdropWindow.cs
MainPage.xaml.cs
但是这一切都是那么的复杂!WinAppSDK for Desktop 中是否会有“BackdropMaterial.ApplyToRootOrPageBackground”实现?

It seems that their implementation at this stage will be more complicated than the original version. The official roadmap says that version 1.2 will try to simplify it.

@BestOwl
Copy link

BestOwl commented May 13, 2022

Will background acrylic be supported on Windows 10?
Just tried it on Windows 10, DesktopAcrylicController.IsSupported() will return false.

@knightmeister
Copy link

Can this issue please get addressed - #4804 - surely it's a simple fix, crashing the app when the user right clicks a textbox is absolutely terrible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
announcement discussion General discussion
Projects
None yet
Development

No branches or pull requests

8 participants