简体   繁体   中英

How to show particular textblock on button click in WPF?

i am working on an application using C# WPF and MVVM.The problem i want to show summary on button click event in textblocks and textblocks are inside ListBox as follows:

 <ListBox>
           <TextBlock
               TextWrapping="Wrap"
               Height="350"
               Text="{Binding ShowVlan}"
            </TextBlock>
          <TextBlock
               TextWrapping="Wrap"
               Height="350"
               Text="{Binding ShowRouting}">
               </TextBlock>
    </ListBox>

I have two buttons and i want that if i click 1st button then 1st textblock should be display and on second button click i want to display second textblock .It is working now but the actual problem is that i want to display to on same positions but these are displaying one after another .I am also attaching screenshot for better understanding.

You could simply put both TextBlock at the same Grid Cell and set their Visibility to true/False based on the selected Button :

<TextBlock x:Name="ShowVlanTb" Visibility="Hidden"
               TextWrapping="Wrap"
               Height="350"
               Text="{Binding ShowVlan}" Grid.Row=1 Grid.Colomn=2
            />
          <TextBlock x:Name="ShowRoutingTb" Visibility="Hidden"
               TextWrapping="Wrap"
               Height="350"
               Text="{Binding ShowRouting}" Grid.Row=1 Grid.Colomn=2>
               />

and on the button Click event handler set the Visiblity to Visible:

ShowVlanTb.Visibility=Visibility.Visible 
ShowRoutingTb.Visibility=Visibility.Hidden

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM