【发布时间】:2017-04-06 22:37:01
【问题描述】:
如何在 StackPanel 中列出所有现有的 ToggleButtons 并在代码隐藏中将其 IsChecked 属性设置为 false?
我开始:
List<ToggleButton> togglebuttons = togglebtnListSp.Children.OfType<ToggleButton>().ToList();
foreach(var item in togglebuttons)
{
item.IsChecked = false;
}
但现在我卡住了,不知道如何确认。
这是我的 XAML:
<!-- Private Customer Rights -->
<StackPanel x:Name="togglebtnListSp">
<GroupBox x:Name="customerRightsGroupBox" Header="Customer Rights" Margin="10,10,10.2,0" VerticalAlignment="Top" Height="108">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Margin="0,0,5,0">
<DockPanel LastChildFill="False">
<Label Content="Can Add:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_add_customer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
<DockPanel LastChildFill="False">
<Label Content="Can Create Assignment:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_add_assignment_customer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
</StackPanel>
<StackPanel Grid.Column="1" Margin="5,0,0,0">
<DockPanel LastChildFill="False">
<Label Content="Can Delete:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_delete_customer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
<DockPanel LastChildFill="False">
<Label Content="Can Edit:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_edit_customer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
</StackPanel>
</Grid>
</GroupBox>
<!-- Firm Customer Rights -->
<GroupBox x:Name="firmCustomerRightsGroupBox" Header="Firmcustomer rights" Margin="10,10,10,0" VerticalAlignment="Top" Height="108">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Margin="0,0,5,0">
<DockPanel LastChildFill="False">
<Label Content="Can Add:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_add_firmcustomer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
<DockPanel LastChildFill="False">
<Label Content="Can create Assignment for firmcustomer" DockPanel.Dock="Left" FontSize="12" />
<ToggleButton x:Name="can_add_assignment_firmcustomer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
</StackPanel>
<StackPanel Grid.Column="1" Margin="5,0,0,0">
<DockPanel LastChildFill="False">
<Label Content="Can Delete:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_delete_firmcustomer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
<DockPanel LastChildFill="False">
<Label Content="Can edit:" DockPanel.Dock="Left" />
<ToggleButton x:Name="can_edit_firmcustomer" DockPanel.Dock="Right"></ToggleButton>
</DockPanel>
</StackPanel>
</Grid>
</GroupBox>
</StackPanel>
我从数据库中读取 false 或 true。但如果我点击“添加”,我希望所有的 ToggleButtons 都是IsChecked="false"
【问题讨论】: