一个射频标准支持多种带宽,多个频点,级联Combobox用两个Dictionary实现
ListView第一列时一个自定义控件,图片根据标准切换,Checkbox默认null,标准下的带宽和频点全部测试完毕后改为 true
采用了 MVVM框架,简单自定义一个Command
internal class RelayCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public Action action;
public RelayCommand(Action action)
{
this.action = action;
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
action?.Invoke();
}
}
internal class RelayCommand<T> : ICommand
{
public event EventHandler CanExecuteChanged;
public Action<T> action;
public RelayCommand(Action<T> action)
{
this.action = action;
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
action?.Invoke((T)parameter);
}
}
Combobox实体。中心频点要做成Checkbox,就加了个IsChecked属性单独封装了
public class ComboboxSignal
{
public ComboboxSignal(string standard, List<string> bandWidthList, List<CenterFreq> centerFreqList)
{
Standard = standard;
BandWidthList = bandWidthList;
CenterFreqList = centerFreqList;
}
public string Standard { get; set; }
public List<string> BandWidthList { get; set; } = new List<string>();
public List<CenterFreq> CenterFreqList { get; set; } = new List<CenterFreq>();
}
public class CenterFreq : INotifyPropertyChanged
{
public event Action<CenterFreq> CheckedChanged;
public event PropertyChangedEventHandler PropertyChanged;
public CenterFreq(string freq, bool isChecked)
{
Freq = freq;
IsChecked = isChecked;
}
private string freq = string.Empty;
public string Freq { get { return freq; } set { freq = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Freq"));}
}
private bool isChecked = false;
public bool IsChecked
{
get { return isChecked; }
set
{
isChecked = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsChecked"));
if (isChecked)
{
CheckedChanged?.Invoke(this);
}
}
}
}
填充数据源,第一个频点默认选中
private static List<ComboboxSignal> m_signalList = new List<ComboboxSignal>();//信号列表
/// <summary>
/// 信号标准
/// </summary>
public List<string> StandardList { get; set; } = new List<string> { "802.11a/g", "802.11b", "802.11n", "802.11ac" };
private void InitSignals()
{
List<CenterFreq> centerFreqList0 = new List<CenterFreq>();
centerFreqList0.Add(new CenterFreq("36/5180M/Hz", true));
centerFreqList0.Add(new CenterFreq("40/5200M/Hz", false));
centerFreqList0.Add(new CenterFreq("44/5220M/Hz", false));
List<CenterFreq> centerFreqList1 = new List<CenterFreq>();
centerFreqList1.Add(new CenterFreq("1/2412M/Hz", true));
centerFreqList1.Add(new CenterFreq("2/2417M/Hz", false));
centerFreqList1.Add(new CenterFreq("3/2422M/Hz", false));
List<CenterFreq> centerFreqList2 = new List<CenterFreq>();
centerFreqList2.Add(new CenterFreq("36/5180M/Hz", true));
centerFreqList2.Add(new CenterFreq("40/5200M/Hz", false));
centerFreqList2.Add(new CenterFreq("44/5220M/Hz", false));
List<CenterFreq> centerFreqList3 = new List<CenterFreq>();
centerFreqList3.Add(new CenterFreq("1/2412M/Hz", true));
centerFreqList3.Add(new CenterFreq("2/2417M/Hz", false));
centerFreqList3.Add(new CenterFreq("3/2422M/Hz", false));
m_signalList.Add(new ComboboxSignal(StandardList[0], new List<string> { "20M" }, centerFreqList0));
m_signalList.Add(new ComboboxSignal(StandardList[1], new List<string> { "20M" }, centerFreqList1));
m_signalList.Add(new ComboboxSignal(StandardList[2], new List<string> { "20M", "40M" }, centerFreqList2));
m_signalList.Add(new ComboboxSignal(StandardList[3], new List<string> { "20M", "40M", "80M", "160M" }, centerFreqList3));
CurrentSignal = m_signalList[0];
ListViewSignalCollection.Add(new ListViewSignal(CurrentSignal));
}
前端绑定,下载Interactivity库,为Combobox提供命令支持
<Grid>
<StackPanel HorizontalAlignment="Left" Margin="50">
<TextBlock Margin="0 10 0 0" Text="{DynamicResource txtLanguage}" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Margin="0 25 0 0" Text="{DynamicResource txtStandard}" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Margin="0 25 0 0" Text="{DynamicResource txtBandWidth}" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Margin="0 25 0 0" Text="{DynamicResource txtCenterFreq}" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Margin="0 50 0 0">
<ComboBox SelectedIndex="0" FontSize="20" Height="50" Width="200" Margin="0 0 0 10">
<i:Interaction.Triggers>