user3660050
user3660050

Reputation: 103

How do I close the window and the buttons?

I have this window that has a "close" button.

enter image description here

When I press the "close" button, it only hides the blue window without hiding the 2 buttons in the image as well.

I want it to hide everything. I've attached the C# code from both classes and also the XAML code of all buttons.

  <local:KinectHoverButton Grid.Column="0" x:Name="leftbtn" Style="{StaticResource KinectHoverButtonScrollLeftStyle}" Click="PageLeftButtonClick" IsEnabled="{Binding ElementName=ControlsBasicsWindow, Path=PageLeftEnabled}"/>
  <local:KinectHoverButton Grid.Column="2" x:Name="right_btn" Style="{StaticResource KinectHoverButtonScrollRightStyle}" Click="PageRightButtonClick" IsEnabled="{Binding ElementName=ControlsBasicsWindow, Path=PageRightEnabled}"/>

The method that hides the buttons:

public partial class ImagesGrid : UserControl
{
    public ImagesGrid()
    {
        InitializeComponent();
        leftbtn.Visibility = System.Windows.Visibility.Hidden;
        right_btn.Visibility = System.Windows.Visibility.Hidden;
    }
    public  void btn()
    {
        leftbtn.Visibility = System.Windows.Visibility.Hidden;
        right_btn.Visibility = System.Windows.Visibility.Hidden;
    }
}

The method that hides the SelectionDisplay window and the call of the btn method

private void OnCloseFullImage(object sender, RoutedEventArgs e)
{
    // Always go to normal state before a transition
    this.Visibility = System.Windows.Visibility.Hidden;
    ImagesGrid img = new ImagesGrid();
    img.btn();
}

The place where I want to make the buttons visible

else if (button.Tag is WineModel)
{
    var wineModel = button.Tag as WineModel;
    var selectionDisplay = new SelectionDisplay(wineModel);
    this.kinectRegionGrid.Children.Add(selectionDisplay);
    leftbtn.Visibility = System.Windows.Visibility.Visible;
    right_btn.Visibility = System.Windows.Visibility.Visible;
    e.Handled = true;
}

EDIT:SelectionDisplay.xaml

<UserControl x:Class="Microsoft.Samples.Kinect.ControlsBasics.SelectionDisplay"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:k="http://schemas.microsoft.com/kinect/2013"

         mc:Ignorable="d" 
         d:DesignHeight="300"
         d:DesignWidth="300"
         Background="Transparent"
         FontFamily="Segoe UI"
         FontSize="30" Loaded="UserControl_Loaded">

<UserControl.Resources>
    <Style TargetType="{x:Type TextBlock}" x:Key="labelStyle">
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="Foreground" Value="Gray"/>
    </Style>
    <Style TargetType="{x:Type TextBlock}" x:Key="valueStyle">
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="FontSize" Value="24"/>
    </Style>
</UserControl.Resources>
<!--<Grid x:Name="layoutRoot">-->
    <Grid x:Name="grid" Background="{StaticResource BlueBrush}" Width="auto">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <Image x:Name="Display" HorizontalAlignment="Left" 
               VerticalAlignment="Center" Height="185" Width="293" Margin="50,0,10,0" Source="{Binding Image}" />
    </Grid>
    <StackPanel Grid.Column="1">
        <TextBlock Text="Origin:" Style="{StaticResource labelStyle}"/>
        <TextBlock Text="{Binding Origin}"  Style="{StaticResource valueStyle}"/>
        <TextBlock Text="Grapes" Style="{StaticResource labelStyle}"/>
        <TextBlock Text="{Binding Grapes}" Style="{StaticResource valueStyle}"/>
        <TextBlock Text="Color" Style="{StaticResource labelStyle}"/>
        <TextBlock Text="{Binding Color}" Style="{StaticResource valueStyle}"/>
        <TextBlock Text="Nose" Style="{StaticResource labelStyle}"/>
        <TextBlock Text="{Binding Nose}" Style="{StaticResource valueStyle}"/>
        <TextBlock Text="Price" Style="{StaticResource labelStyle}"/>
        <TextBlock Text="{Binding Price, StringFormat='C'}" Style="{StaticResource valueStyle}"/>
    </StackPanel>
    <Grid Grid.Column="2">
        <k:KinectCircleButton Style="{StaticResource CancelButtonStyle}" Foreground="White" Click="OnCloseFullImage"
                              VerticalAlignment="Top"/>
    </Grid>        
</Grid>
<!--</Grid>-->

Upvotes: 1

Views: 130

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61339

This code (from the close handler)

ImagesGrid img = new ImagesGrid();
img.btn();

Creates a brand new "ImagesGrid", then instructs it to hide. You need to get a reference to the existing "ImagesGrid" and invoke the btn method on it.

Since they are tied together, I would make the "scroll" buttons part of the same user control that contains the "close" button and avoid the issue entirely. If you really want to pass the reference around:

If your main user control has an "ImagesGrid"

<local:ImagesGrid Name="ScrollButtons"/>

Then you would write:

ScrollButtons.btn();

Now of course, this causes a problem because your other user control likely doesn't have access to "ScrollButtons" so you need to pass a reference to your "View" class (or the ScrollButtons object itself) when creating the "main" user control, etc. It gets very messy, which is why I would just combine the two!

Upvotes: 2

Related Questions