Visual State manager for adaptive size does not work with Window
See original GitHub issueApplication: WinUI 3 Nuget: Project Reunion Visual Studio 2019 PREVIEW.
I’m trying to set adaptive visual states to a Window (WinUi Desktop) for when the app is resized.
VisualStateManager works when using a Page (winUI) But does not work if it is a Window.
Is this meant to be?
<x:Double x:Key="NarrowMinWidth">0</x:Double>
<x:Double x:Key="NormalMinWidth">580</x:Double>
<x:Double x:Key="WideMinWidth">1100</x:Double>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveVisualStateGroup">
<VisualState x:Name="VisualStateNarrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myButton.Width" Value="40"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateNormal">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myButton.Width" Value="80"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myButton.Width" Value="150"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</Grid>
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Visual state not firing when reducing window
I have 3 visual states , with adaptivetrigger. When windows is increasing they firing well. But if window is reducing from biggest state...
Read more >AdaptiveTrigger Class (Microsoft.UI.Xaml) - Windows
Use AdaptiveTriggers to create rules that automatically trigger a VisualState change when the window is a specified height or width. When you use ......
Read more >It is impossible to set column width using ...
Hi, I would like to give a few columns a fixed width depending on the screen width. The remaining columns will take the...
Read more >Using AdaptiveTrigger to Build Adaptive UIs in Windows 10
You use AdaptiveTrigger in conjunction with Visual State Manager to adapt the UI to screens and windows of various sizes. For example, you...
Read more >Windows 10 Development - Adaptive UI
StateTriggers allows the developer to check certain conditions like the window height or window width and then the VisualState.Setters APIs define visual states...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is still an issue and confusing. On https://docs.microsoft.com/en-gb/windows/apps/design/controls/navigationview there seems to be made no distinction between Page and Window and purely from that documentation I still don’t see why we can’t use the VisualStateManager. Is there a workaround if I don’t want to use Frames and Pages? I don’t need the navigation components, I just want to have a menu that sits on top and collapses into a hamburger if the window width falls below a certain threshold.
I agree with you @mdtauk and @Elmarcotoro, this might be good to explain in the documentation. I’m not sure though who would be the right person to direct this to, @ranjeshj do you happen know who is the right person for this?