c# - Caliburn.Micro,当键入非现有项目时,SelectedItem 不会在 EditableCombobox 上触发
问题描述
一旦用户在带有绑定项目列表的 ComboBox 中键入信息,我就会尝试设置 CanExecute 方法。I can disnable the button with CanAddCustomer (name is AddCustomer) without issues when there is an existing item selected; 当输入为空(selectedCustomer 为空)时,禁用按钮也有效;但这些事件似乎并没有在输入框中免费输入
- 禁用因为空,
- 已禁用,因为现有客户
- 应该启用,因为不存在条目
组合框的 WPF
<ComboBox
x:Name="Customers" Height="40"
DisplayMemberPath="CustomerName"
Controls:TextBoxHelper.UseFloatingWatermark="False"
Controls:TextBoxHelper.Watermark="Select a Customer"
IsEditable="True"
MaxDropDownHeight="125"
Margin="0 0 15 0"
Grid.Column="0"
/>
ViewModel 中的数据:
private Customer _selectedCustomer ;
private string _customer;
public string Customer
{
get { return _customer; }
set {
_customer = value;
NotifyOfPropertyChange(() => CanAddCustomer);
}
}
public Customer SelectedCustomer
{
get { return _selectedCustomer; }
set {
_selectedCustomer = value;
NotifyOfPropertyChange(() => CanAddCustomer);
GetAllOrdersPerCustomer();
}
}
public bool CanAddCustomer
{
get
{
Customer cs = SelectedCustomer;
if (cs == null && string.IsNullOrEmpty(Customer))
{
return false;
} else if (cs != null ) {
return false;
} else
{
return true;
}
}
}
public void AddCustomer()
{
Debug.WriteLine("You cliked");
}
我知道这个问题,当我调试项目时,我可以看到“SelectedCustomer”没有被触发......但是......然后我如何引用文本框中的文本?该public string Customer
属性是我的尝试,但这只是 selectedItem 的值
解决方案
当您键入一个不存在ComboBox
于其.SelectedItem
null
ItemsSource
您已经实现了您的视图模型,以确实启用ComboBox
whenSelectedItem
为 null 并且 theComboBox
为空。
在这种情况下,也许你最好绑定到的Text
属性。ComboBox
它应该返回当前在TextBox
.
该SelectedItem
属性只能设置为ItemsSource
.
推荐阅读
- python - 将带有项目和值列表的熊猫列拆分为单独的列,并将项目作为列标题
- reactjs - 根据当前的 SELECT OPTION VALUE 设置标题 onSubmit - 反应
- nltk - 极性和主观性的 TextBlob 0 值
- javascript - 为什么不替换第二个数组 last13 中的所有字母?
- javascript - 在实用函数 Redux JS 中更新值后立即调度异步操作和 getState
- encryption - 在 HA 代理中使用 aes_gcm_dec 解密 HTTP 标头
- ios - 通过的标签不出现
- python - 如何使用 python 使点击事件通过窗口?
- elasticsearch - 同一查询中不同搜索的 Elasticsearch 聚合
- wordpress - Wordpress Lightbox 仅显示第一张图片