根据文本框文本更改组合框项目列表 [英] Change combo box item list depending on the Textbox Text
本文介绍了根据文本框文本更改组合框项目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网格中有两列:
Name(Textbox) ---- ParentList(combobox) / strong>
Name(Textbox) ---- ParentList(combobox).
A -----------------------它应该只包含B和C
A ----------------------- It should comprise of only B and C
B ----------------------- A和C
B ----------------------- A and C
C ----------------------- A和B
C ----------------------- A and B
我的ParentList包含{A,B,C}。
My ParentList contains {A,B,C}.
如何根据文本框中的文本从列表中隐藏特定项?
我的代码的XAML是:
XAML for my code is:
<Grid>
<StackPanel >
<ListView>
<ListView.View>
<GridView >
<GridViewColumn Header="Name" >
<GridViewColumn.CellTemplate >
<DataTemplate >
<WrapPanel >
<TextBox x:Name="txName" Text="{Binding Name}" />
</WrapPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Parent List" >
<GridViewColumn.CellTemplate >
<DataTemplate >
<WrapPanel >
<ComboBox x:Name="cbParentId" ItemsSource="{Binding Path=ParentList,ElementName=UI}" />
</WrapPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Grid>
推荐答案
写一个GotFocus事件并对所需项应用可见性。
The simple and best solution [for me] would be to write a 'GotFocus' event and apply the Visibility on the required item.
private void combobox_GotFocus_1(object sender, RoutedEventArgs e)
{
var combobox = sender as ComboBox;
if (combobox == null) return;
var model = combobox.DataContext as Model;
foreach (var item in combobox.ItemsSource)
{
if (item.Equals(model.Name))
{
var comboboxItem = combobox.ItemContainerGenerator.ContainerFromItem(item) as ComboBoxItem;
if (comboboxItem != null)
comboboxItem.Visibility = Visibility.Collapsed;
}
}
}
这篇关于根据文本框文本更改组合框项目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文