0
我写了一个应用程序,其中有一个ToggleButton
和UI上的其他几个控件。当ToggleButton
的状态为IsChecked
时,我想要实现两件事。ToggleButton IsChecked触发器
1) Hide few controls e.g. button1,button2 etc. in below example 2) Change 'Content' of ToggleButton to 'Show'
我能做到不点2,但不知道如何访问其他控制和设置Trigger
内它们的属性。我的XAML代码如下所示:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="108*" />
<RowDefinition Height="107*" />
<RowDefinition Height="96*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="209*" />
<ColumnDefinition Width="161*" />
<ColumnDefinition Width="133*" />
</Grid.ColumnDefinitions>
<ToggleButton x:Name="tg"
Height="20"
Width="80"
Grid.Column="1"
Margin="2,38,79,49"
Grid.Row="1">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Content"
Value="Hide" />
<Style.Triggers>
<Trigger Property="IsChecked"
Value="true">
<Setter Property="{Binding ElementName=Button1,Path=Content}"
Value="Show" />
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
<Button Content="Button1"
Height="23"
HorizontalAlignment="Left"
Margin="45,28,0,0"
Name="button1"
VerticalAlignment="Top"
Width="75" />
<Button Content="Button2"
Height="23"
HorizontalAlignment="Left"
Margin="38,28,0,0"
Name="button2"
VerticalAlignment="Top"
Width="75"
Grid.Column="1" />
</Grid>
问题:当用户点击切换按钮“TG”我想隐藏“按钮1”,“按钮2”而当切换按钮变为状态取消选中再次显示BUTTON1。
如何切换button1的可见性与ToggleButton
的IsChecked
属性?
这是否意味着我不得不写这篇文章的每一个按钮,我想要显示/隐藏。随着隐藏按钮,我也想改变网格列的宽度。其实我试图找到解决方案http://stackoverflow.com/questions/16632068/zooming-in-specific-part-of-screen-in-wpf quesion。 – user2243747
一个选项可能是将所有按钮/元素放入容器中并显示/隐藏该容器。 – Jatin