Replies: 5 comments
-
I think that you've probably copied our template which includes some custom conditional xaml. You'll notice that OverflowContentRootClipTransform is infact defined twice in the template, once in the grid prefixed with Contract12Present and once in the grid prefixed with Contract12NotPresent. Winui2 does conditional xaml as a preprocessing step so the xaml complier never sees this, however your project will not have this version of conditional xaml. Contract 12 is the 21h1 version of windows, if you are targetting exclusively contract 12+ or contract 11- then you could just remove one of the grids from your copied template. If you are targetting more than that this will be difficult to do.... Ideally you could just override the resource named AppBarButtonOverflowStyle and AppBarToggleButtonOverflowStyle, however due to some.. quirks.. with how the resource system works and how Winui2 sits in the project structure these resources aren't actually overridable in their current state. We could change https://github.com/microsoft/microsoft-ui-xaml/blob/main/dev/CommonStyles/CommandBar_themeresources.xaml#L960-L961 to reference these resources via a {ThemeResource} markup extension and then you would be able to override the resource at the page level, but not the application level, which I think it going to be the best solution, but wont be available until we perform the fix and do another release. As for why this is so hard... its complicated. Winui2 is just a nuget package that sits on top of the framework and contains some new types and some styles for old types. Given this model, there is no way for us to specify that these new styles are the default styles for the controls in the system, since the default styles need to be included in the same package. So when you inherrit from a control you are changing the type which causes the non-default winui2 styles to not be applicable anymore, thus needing the based on style. Then there is the issue of resource lookups which is also very complicated, but basically because all of these resources live in the same dictionary within the app.xaml's resources you have to be extremely percise with our your resources are set up for the lookup to find overrides. Finally the conditional xaml the winui2 project utilizes was made because it is much more performant than traditional conditional xaml. It has the same syntax as the real conditional xaml, but we've needed to add new features that we needed for some of our types, which is why it does not function in your project when you copied it. This is a real mess, but Winui3 will solve a lot of the issues... |
Beta Was this translation helpful? Give feedback.
-
#5540 this PR should allow you to override the resource with your own style, but I'm realizing now that might not even fix your issue, since the CommandBar style still specifies the wrong target type, even if you change the based on style... |
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed explanation.
It is a mess, and from what I read noone knows when WinUI3 support for UWP will happen, or if it will happen at all... Coming back to my original problem: How would I ideally do some |
Beta Was this translation helpful? Give feedback.
-
Just got this issue with my descendant of AppBarToggleButton while upgrading to Win11-like styles from WinUI 2.7. P.S. |
Beta Was this translation helpful? Give feedback.
-
Working solution for the problem:
P.S. Unfortunately, visual states are not changed for AppBar[Toggle]Button descendants that are in overflow menu due to the dynamic overflow, only for statically SecondaryCommands. |
Beta Was this translation helpful? Give feedback.
-
In my apps I subclass
AppBarButton
in order to set the tooltip & property for screenreader to the same value as theAppBarButton
's label:With WinUI 2.5 and before, I was able to set the correct styles to my subclass type like this:
No with WinUI 2.6, the default
AppBarButton
style changed and I tried to use this:The problem is, that the style of the
AppBarButton
needs to be changed when it is placed in an overflow menu. This is done in the defaultCommandBar
style here: https://github.com/microsoft/microsoft-ui-xaml/blob/main/dev/CommonStyles/CommandBar_themeresources.xaml#L960-L961Now I thought, well this is quite tedious but I go ahead and try to copy & edit the whole
DefaultCommandBarStyle
and change those lines toI put that edited style in a new file in my project and tried to compile it, but it resulted in errors:
How would I be able to resolve that error?
And why is subclassing a class (like
AppBarButton
) while keeping the default style so difficult in the first place?Beta Was this translation helpful? Give feedback.
All reactions