How to disable the view?
I am following the buttons/MVVM example, and launching a game round upon clicking 'start'. I would also like to hide the view. I tried _view.enabled = false, but this doesn't work in the OnStart() routine. I have to think I'm missing something really obvious here. Is there another simple way to have a 'main menu' like this and hide it during gameplay for a period of time?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: How to disable the view?
If you want to hide it from the view model logic, you can expose a property that indicates if the menu should be visible. Then you can bind that property in the xaml to the Visibility of the menu and set it to Collapsed.
Another option is to use a trigger in the button to launch an animation that hides the menu:
Is this what you are looking for?
Code: Select all
<Window ...>
<Window.Resources>
<BooleanToVisibilityConverter x:Key="visConverter"/>
...
</Window.Resources>
<Grid x:Name="LayoutRoot" Visibility="{Binding ShowMenu, Converter={StaticResource visConverter}}">
...
</Grid>
</Window>Code: Select all
<Window ...>
<Window.Resources>
<Storyboard x:Key="HideMenuAnim">
...
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LayoutRoot">
<DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
...
</Window.Resources>
<Grid x:Name="LayoutRoot">
...
<Button x:Name="StartButton"...>
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:ControlStoryboardAction Storyboard="{StaticResource HideMenuAnim}" ControlStoryboardOption="Play"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button>
</Grid>
</Window>Who is online
Users browsing this forum: No registered users and 5 guests