question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Visual State manager for adaptive size does not work with Window

See original GitHub issue

Application: 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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
lennartb-commented, Dec 10, 2021

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.

0reactions
chingucodingcommented, Jan 6, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found