【发布时间】:2016-08-23 11:15:02
【问题描述】:
我需要在 TextBox 中添加 ListBox,即 CHIPS
参考屏幕截图:(期望)
只考虑视图模型:
public class Person
{
private ObservableCollection<string> _personList = new ObservableCollection<string>();
public ObservableCollection<string> PersonList
{
get { return _personList; }
set
{
_personList = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("PersonList"));
}
}
private string _personStr = String.Empty;
public string PersonStr
{
get { return _personStr; }
set
{
_personStr = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("PersonStr"));
}
}
public Person()
{
PersonList.Add("IR-Punch");
PersonList.Add("Stack-Overflow");
}
public ICommand BTextCommand
{
get
{
return new DelegateCommand(AppendString);
}
}
public void AppendString()
{
PersonList.Add(PersonStr);
}
}
有效的 XAML 源代码:
<ItemsControl ItemsSource="{Binding PersonList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding }" TextWrapping="Wrap"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBox Text="{Binding PersonStr}" Width="160" VerticalAlignment="Center" />
<Button Command="{Binding BTextCommand}" Content="Add" />
请帮助我如何在TextBox 中添加ListBox。我照顾赛特尔。我期待核心思想。
【问题讨论】:
-
您可以尝试从代码后面并以编程方式在文本框中添加列表框
-
这就是我要问的想法如何写...
-
有点不清楚你在这里要求什么。您是说要开始在文本框中输入内容并在下拉菜单中显示选项列表吗?
标签: wpf xaml listbox wpf-controls custom-controls