michaelh
Topic Author
Posts: 1
Joined: 22 Oct 2023, 15:05

How to disable the view?

24 Oct 2023, 03:10

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?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: How to disable the view?

24 Oct 2023, 19:55

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.
<Window ...>
  <Window.Resources>
    <BooleanToVisibilityConverter x:Key="visConverter"/>
    ...
  </Window.Resources>
  <Grid x:Name="LayoutRoot" Visibility="{Binding ShowMenu, Converter={StaticResource visConverter}}">
    ...
  </Grid>
</Window>
Another option is to use a trigger in the button to launch an animation that hides the menu:
<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>
Is this what you are looking for?

Who is online

Users browsing this forum: No registered users and 5 guests