none
Make main window grids visible when a button in user control clicked. RRS feed

  • Question

  • In my mainwindow there is a list view & when select option user controls will display.Buttons are in user controls & when a button select I want to visible a grid in mainwindow.How can I do it.please explain with codes.
    Sunday, November 17, 2019 1:48 AM

Answers

  • Hi,

    Do you want a demo like this?

     <Grid >
            <Grid.ColumnDefinitions >
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <ListView Name="list1" Grid.Row="0" Grid.Column="0">
                <ListViewItem>1</ListViewItem>
                <ListViewItem PreviewMouseDown="ListViewItem_PreviewMouseDown" >2</ListViewItem>
                <ListViewItem>3</ListViewItem>
              
            </ListView>
            
            <UserControl Name="us1" Grid.Row="0" Grid.Column="1" Visibility="Hidden" Width="100" Height="50">
                <Button Content="btn1" Click="Button_Click"/>
            </UserControl>
            <Grid x:Name="grid1" Grid.Row="1" Grid.Column="1" Background="Red" Visibility="Hidden">
                
            </Grid>
            
        </Grid>
      public MainWindow()
            {
                InitializeComponent();
            }
         
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                grid1.Visibility = Visibility.Visible;
            }
    
            private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                us1.Visibility = Visibility.Visible;
            }


    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 18, 2019 2:53 AM
    Moderator

All replies

  • In my mainwindow there is a list view & when select option user controls will display.Buttons are in user controls & when a button select I want to visible a grid in mainwindow.How can I do it.please explain with codes.
    Sunday, November 17, 2019 1:54 AM
  • My.Windows.winYouWindow.CallFunction()

    https://awwshop.wikidot.com

    Sunday, November 17, 2019 2:27 AM
  • Hi,

    Do you want a demo like this?

     <Grid >
            <Grid.ColumnDefinitions >
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <ListView Name="list1" Grid.Row="0" Grid.Column="0">
                <ListViewItem>1</ListViewItem>
                <ListViewItem PreviewMouseDown="ListViewItem_PreviewMouseDown" >2</ListViewItem>
                <ListViewItem>3</ListViewItem>
              
            </ListView>
            
            <UserControl Name="us1" Grid.Row="0" Grid.Column="1" Visibility="Hidden" Width="100" Height="50">
                <Button Content="btn1" Click="Button_Click"/>
            </UserControl>
            <Grid x:Name="grid1" Grid.Row="1" Grid.Column="1" Background="Red" Visibility="Hidden">
                
            </Grid>
            
        </Grid>
      public MainWindow()
            {
                InitializeComponent();
            }
         
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                grid1.Visibility = Visibility.Visible;
            }
    
            private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                us1.Visibility = Visibility.Visible;
            }


    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 18, 2019 2:53 AM
    Moderator
  • In my mainwindow there is a list view & when select option user controls will display.Buttons are in user controls & when a button select I want to visible a grid in mainwindow.How can I do it.please explain with codes.
    Hi   Rashmi Kaushalya,

    In your UserControl, you can use the Application.Current.MainWindow method to find the MainWindow.
    MainWindow window =  (MainWindow)Application.Current.MainWindow;
    And then, set the mainwindow's grid visible property.
    window.grids.Visibility = System.Windows.Visibility.Visible;
    Best regards

    Yong Lu
     

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 18, 2019 6:45 AM
    Moderator