我需要在我的代码中添加一些逻辑,它将BooleanToVisibilityConverter设置为true或false,具体取决于我的MVVM模型中的XAML组合框中的选定值。更复杂的是,我实际上有2个组合框。组合框2中显示的列表取决于在组合框1中选择的值
组合框1 XAML
<ComboBox Margin="103,6,0,24"
x:Name="FirstOne"
Grid.Column="1"
DisplayMemberPath="SetCriteria"
ItemsSource="{Binding CriteriaList}"
SelectedItem="{Binding SelectedCriteriaLists, Mode=TwoWay}"/>
组合框1,代码隐藏
public void SearchViewModel()
{
this.CriteriaList = new ObservableCollection<SearchCriteriaList>
{
new SearchCriteriaList {SetCriteria = "Date Range"},
new SearchCriteriaList {SetCriteria = "Gateway"},
new SearchCriteriaList {SetCriteria = "Direction"}
};
this.OperatorList = new ObservableCollection<SearchOperatorLists>();
}
组合框2 XAML
<ComboBox Margin="103,41,1,40"
x:Name="SecondOne"
Grid.Column="1"
Grid.RowSpan="2"
DisplayMemberPath="OperatorName"
ItemsSource="{Binding OperatorList}"/>
组合框2,代码隐藏
private readonly List<SearchOperatorLists> dateOperatorList = new List<SearchOperatorLists>
{
new SearchOperatorLists {OperatorName = "Today"},
new SearchOperatorLists {OperatorName = "Between"},
new SearchOperatorLists {OperatorName = "Last Month"}
};
private readonly List<SearchOperatorLists> gatewayOperatorList = new List<SearchOperatorLists>
{
new SearchOperatorLists {OperatorName = "CCSUK"},
new SearchOperatorLists {OperatorName = "MCP"},
new SearchOperatorLists {OperatorName = "CNS"},
new SearchOperatorLists {OperatorName = "Email"}
};
private readonly List<SearchOperatorLists> directionOperatorList = new List<SearchOperatorLists>
{
new SearchOperatorLists {OperatorName = "In"},
new SearchOperatorLists {OperatorName = "Out"}
};
private SearchCriteriaList selectedCriteriaList;
确定如此,只要在FirstOne组合框(日期范围,网关或方向)中选择了一个值,就会使用onPropertyChanged事件组合框2显示相应的列表(dateOperatorList,gatewayOperatorList,directionOperatorList)
我的要求是在组合框2中捕获一个值,说“Between”,然后将我的BooleanToVisibilityConverter设置为true。在这种情况下,将显示2个日期选择器。
非常感谢任何指针。
答案 0 :(得分:1)
而是使用对象模型,其中主要项目(第一个组合)具有Children
属性,其中包含第二个Combobox
的项目。
这会使您的第二个Combobox
Binding
成为:
<ComboBox Margin="103,41,1,40"
x:Name="SecondOne"
Grid.Column="1"
Grid.RowSpan="2"
DisplayMemberPath="OperatorName"
ItemsSource="{Binding SelectedCriteriaLists.Children}"/>
如果依赖对象列表发生变化,从长远来看,更简单,更少维护问题。