C# 更新切换按钮检查其中一个按钮切换时的状态
我有一个包含2个字段的XamDataGrid。在第二个字段中,我有切换按钮。单击C# 更新切换按钮检查其中一个按钮切换时的状态,c#,wpf,infragistics,C#,Wpf,Infragistics,我有一个包含2个字段的XamDataGrid。在第二个字段中,我有切换按钮。单击切换按钮时,值设置正确。但在任何时候,用户都应该能够在所有记录中只检查一个ToggleButton。默认属性的集合逻辑中的数据工作正常。但是我需要为DataSource中的其他项设置默认值 使用单选按钮而不是切换按钮将是理想的解决方案。但有可能所有记录都不是默认记录。所以我想要一个解决方案,当其中一个字段变为true时,使其他默认字段变为false 字段的XAML: <igWPF:Field Name="Def
切换按钮
时,值设置正确。但在任何时候,用户都应该能够在所有记录中只检查一个ToggleButton
。默认属性的集合逻辑中的数据工作正常。但是我需要为DataSource中的其他项设置默认值
使用单选按钮
而不是切换按钮
将是理想的解决方案。但有可能所有记录都不是默认记录。所以我想要一个解决方案,当其中一个字段变为true时,使其他默认字段变为false
字段的XAML:
<igWPF:Field Name="Default" Width="84">
<igWPF:Field.Settings>
<igWPF:FieldSettings CellValuePresenterStyle="{StaticResource ButtonDefault}" />
</igWPF:Field.Settings>
</igWPF:Field>
您可以使用相同的事件处理程序检查和取消检查切换按钮事件。
然后只需设置一个if条件—(if toggle_btn.isChecked)‘checked code’或者‘unchecked code’我试过了。但不知道为什么它不会触发未检查。
<Style x:Key="ButtonDefault" TargetType="{x:Type igWPF:CellValuePresenter}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}">
<ToggleButton Content="Default"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Width="80"
Height="36"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class LanguageSettingItem : INotifyPropertyChanged
{
private string name;
private bool isDefault;
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get { return this.name; }
set { this.name = value; PropChanged("Name"); }
}
public bool Default
{
get { return this.isDefault; }
set { this.isDefault= value; PropChanged("Default"); }
}
public void PropChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}