microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.27k stars 674 forks source link

PrimaryButtonStyle cannot be set for ContentDialog #1899

Closed eyalkapah closed 4 years ago

eyalkapah commented 4 years ago

Describe the bug Cannot set PrimaryButtonStyle on a ContentDialog via code.

var contentDialog = new ContentDialog();
contentDialog.PrimaryButtonStyle = (Style)Application.Current.Resources["PrimaryButtonStyle"];

gets an exception: System.InvalidCastException: 'Unable to cast object of type 'Windows.UI.Xaml.Controls.ContentDialog' to type 'Windows.UI.Xaml.Controls.IContentDialog2'.'

Steps to reproduce the bug Define a ContentDialog in code and try set its PrimaryButtonStyle.

Expected behavior Primary button will get the requested style.

Version Info

NuGet package version: Microsoft.UI.Xaml 2.1.190606001

Windows 10 version Saw the problem?
November 2019 Update (18363) No
Creators Update (15063) No
Anniversary Update (14393) Yes **
Device form factor Saw the problem?
Desktop Yes

Additional context The problems occurs on 14393. Although it should work since target version is 17763

ranjeshj commented 4 years ago

@eyalkapah I am not able to reproduce this issue. Is PrimaryButtonStyle a style you have provided ? Can you attach a repro app ?

eyalkapah commented 4 years ago

@ranjeshj please follow the link for repro

https://github.com/eyalkapah/ContentDialogBug

notice that the problem is on 14393 only.

Thanks,

StephenLPeters commented 4 years ago

@eyalkapah the primary button style api was introduced with v10.0.15063.0 so unfortunately you will not be able to get this to work on 14393 and we won't be able to address the bug. However with WinUI 3.0 this will no longer be an issue. I would suggest making a version check within your app code before making this call. https://docs.microsoft.com/en-us/uwp/api/windows.foundation.metadata.apiinformation

eyalkapah commented 4 years ago

isn't the purpose of the library? bring features to earlier versions?

"Updated versions of existing controls: The library also contains updated versions of existing Windows platform controls that you can use with earlier versions of Windows 10."

ranjeshj commented 4 years ago

@eyalkapah ContentDialog is a type from coming from the OS, not WinUI2 codebase (hint that it is Windows.UI.Xaml.Controls.ContentDialog and not Microsoft.UI.Xaml..) hence the issue with that not working downlevel. The plan is to move those types here in WinUI3 so you won't hit this then.