[英]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: 我正在使用C#WPF和MVVM开发应用程序。我想在文本块和文本块中的按钮单击事件上显示摘要的问题在ListBox内,如下所示:
<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
放在同一网格单元中,然后根据所选的Button将它们的可见性设置为true / False:
<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: 并在按钮Click事件处理程序上将“可见性”设置为“可见”:
ShowVlanTb.Visibility=Visibility.Visible
ShowRoutingTb.Visibility=Visibility.Hidden
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.