update comboBox
/// <summary>
/// AutoCompleteComboBox
/// </summary>
public class AutoCompleteComboBox : ComboBox
{
#region DependencyProperty
public string WaterMark
{
get { return (string)GetValue(WaterMarkProperty); }
set { SetValue(WaterMarkProperty, value); }
} // Using a DependencyProperty as the backing store for WaterMark. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WaterMarkProperty =
DependencyProperty.Register("WaterMark", typeof(string), typeof(AutoCompleteComboBox), new PropertyMetadata(null, new PropertyChangedCallback(OnWaterMarkChanged))); public bool? IsNull
{
get { return (bool?)GetValue(IsNullProperty); }
set { SetValue(IsNullProperty, value); }
} // Using a DependencyProperty as the backing store for IsNull. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsNullProperty =
DependencyProperty.Register("IsNull", typeof(bool?), typeof(AutoCompleteComboBox), new PropertyMetadata(null)); public bool? SetFocuse
{
get { return (bool?)GetValue(SetFocuseProperty); }
set { SetValue(SetFocuseProperty, value); }
} // Using a DependencyProperty as the backing store for SetFocuse. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SetFocuseProperty =
DependencyProperty.Register("SetFocuse", typeof(bool?), typeof(AutoCompleteComboBox), new PropertyMetadata(null, new PropertyChangedCallback(OnSetFocuseChanged))); public bool IsAllowNull
{
get { return (bool)GetValue(IsAllowNullProperty); }
set { SetValue(IsAllowNullProperty, value); }
} // Using a DependencyProperty as the backing store for IsAllowNull. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsAllowNullProperty =
DependencyProperty.Register("IsAllowNull", typeof(bool), typeof(AutoCompleteComboBox), new PropertyMetadata(true, new PropertyChangedCallback(OnIsAllowNullChanged))); private static void OnIsAllowNullChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ } #endregion #region Event
private static void OnWaterMarkChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{ } private static void OnSetFocuseChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
AutoCompleteComboBox wm = obj as AutoCompleteComboBox; if (e.NewValue != null && wm.EditableTextBox != null)
{ if ((bool)e.NewValue == true && wm.EditableTextBox.IsFocused != true)
{
wm.EditableTextBox.Focus();
} }
} public IList DataSource
{
get { return (IList)GetValue(DataSourceProperty); }
set { SetValue(DataSourceProperty, value); }
} // Using a DependencyProperty as the backing store for DataSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DataSourceProperty =
DependencyProperty.Register("DataSource", typeof(IList), typeof(AutoCompleteComboBox), new UIPropertyMetadata(null, new PropertyChangedCallback(OnDataSourceChanged))); private static void OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
AutoCompleteComboBox a = d as AutoCompleteComboBox;
//if (a.IsAllowNull)
//{
a.Items.Clear();
if (a.DataSource != null)
{ Type b = null; foreach (var item in a.DataSource)
{
if (b == null)
{
b = item.GetType();
object o = Activator.CreateInstance(b);
//o.GetType().GetProperty(a.DisplayMemberPath).SetValue(o, "----Select----", null);
a.Items.Add(o);
}
a.Items.Add(item);
} }
else
{
a.ItemsSource = null;
} //} } protected override void OnDropDownOpened(EventArgs e)
{
base.OnDropDownOpened(e);
if (this.HasItems)
{
this.Items[].GetType().GetProperty(this.DisplayMemberPath).SetValue(this.Items[], "----Select----", null);
} } protected override void OnDropDownClosed(EventArgs e)
{
base.OnDropDownClosed(e);
if (this.SelectedIndex == )
{
//this.SelectedItem = null;
//this.SelectedItem = null;
//this.Text = null;
//this.SelectedValue = null;
this.SelectedIndex = -;
}
} public override void OnApplyTemplate()
{
base.OnApplyTemplate(); //load the text box control
if (this.EditableTextBox != null && this.MyWaterMarkTextBlock != null)
{
if (SetFocuse == true)
{
if (!this.EditableTextBox.IsFocused)
{
this.EditableTextBox.Focus();
} }
this.EditableTextBox.TextChanged += new TextChangedEventHandler(EditableTextBox_TextChanged);
this.EditableTextBox.GotFocus += EditableTextBox_GotFocus;
this.Loaded += AutoCompleteComboBox_Loaded;
} } void AutoCompleteComboBox_Loaded(object sender, RoutedEventArgs e)
{ if (string.IsNullOrWhiteSpace(this.Text))
{ this.MyWaterMarkTextBlock.Visibility = Visibility.Visible;
//this.MyWaterMarkTextBlock.Text = WaterMark;
this.IsNull = false;
}
else
{ this.MyWaterMarkTextBlock.Visibility = Visibility.Collapsed;
//this.MyWaterMarkTextBlock.Text = WaterMark;
this.IsNull = true;
}
try
{
//if (this.HasItems)
//{
// this.Items[0].GetType().GetProperty(this.DisplayMemberPath).SetValue(this.Items[0], "----Select----", null);
//}
//if (!this.IsAllowNull)
//{
// this.EditableTextBox.IsEnabled = false;
//}
}
catch (Exception)
{ } } void EditableTextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (this.MyWaterMarkTextBlock.Visibility == Visibility.Visible)
{
// this.Text = null;
this.MyWaterMarkTextBlock.Visibility = Visibility.Collapsed;
//this.MyWaterMarkTextBlock.Text = WaterMark;
}
this.IsDropDownOpen = true;
} protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e); if (this.SelectedIndex == )
{
this.SelectedIndex = -;
} } void EditableTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (this.EditableTextBox.IsFocused && this.IsDropDownOpen == false)
{ this.IsDropDownOpen = true;
}
if (string.IsNullOrWhiteSpace(this.Text))
{
if (!this.EditableTextBox.IsFocused)
{
this.MyWaterMarkTextBlock.Visibility = Visibility.Visible;
// this.MyWaterMarkTextBlock.Text = WaterMark; }
this.IsNull = false; }
else
{
this.IsNull = true;
this.MyWaterMarkTextBlock.Visibility = Visibility.Collapsed;
// this.MyWaterMarkTextBlock.Text = WaterMark; } } void SimpleAutoCompleteComboBox_LostFocus(object sender, RoutedEventArgs e)
{
this.IsDropDownOpen = false;
// to prevent misunderstanding that user has entered some information
if (this.SelectedIndex == - || this.SelectedIndex == )
{
this.Text = null;
this.SelectedItem = null;
this.SelectedValue = null;
this.MyWaterMarkTextBlock.Visibility = Visibility.Visible;
this.IsNull = false;
// this.MyWaterMarkTextBlock.Text = WaterMark; }
// syncronize text
else
{
this.Text = this.SelectedText;
this.IsNull = true;
}
// release timer resources try
{
this.EditableTextBox.CaretIndex = ;
}
catch { }
} #endregion #region Construtor
static AutoCompleteComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AutoCompleteComboBox), new FrameworkPropertyMetadata(typeof(AutoCompleteComboBox))); } public AutoCompleteComboBox()
{
this.StaysOpenOnEdit = true;
this.IsEditable = true;
this.IsTextSearchEnabled = true;
this.LostFocus += SimpleAutoCompleteComboBox_LostFocus;
this.IsAllowNull = true; }
#endregion protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
{
base.OnItemsSourceChanged(oldValue, newValue);
} #region property
/// <summary>
/// Gets the waterMark .
/// </summary>
protected TextBlock MyWaterMarkTextBlock
{
get
{
return base.GetTemplateChild("PART_MyWaterMarkTextBlock") as TextBlock;
}
} /// <summary>
/// Gets the text box in charge of the editable portion of the combo box.
/// </summary>
protected TextBox EditableTextBox
{
get
{
return base.GetTemplateChild("PART_EditableTextBox") as TextBox;
}
} private string SelectedText
{
get
{
try
{
if (this.SelectedIndex == -) return null; if (this.SelectedItem != null)
{
return this.SelectedItem.GetType().GetProperty(this.DisplayMemberPath).GetValue(this.SelectedItem, null).ToString();
}
else
{
return null;
}
}
catch (System.Exception)
{ return null;
} }
}
#endregion }
update comboBox的更多相关文章
- Flyout中ComboBox失效
参见这篇文章:https://blogs.msdn.microsoft.com/wsdevsol/2016/09/14/combobox-from-an-appbarbutton-loses-mous ...
- combobox 属性、事件、方法
一 .combobox 属性.事件.方法公共属性 名称 说明 AccessibilityObject 获取分配给该控件的 AccessibleObject. AccessibleDefaultActi ...
- WPF standard ComboBox Items Source Change Issue
Today I encountered an issue with the WPF standard CombBox where if the bound ItemsSource (collectio ...
- C#中combobox 控件属性、事件、方法
一 .combobox 属性.事件.方法公共属性 名称 说明 AccessibilityObject 获取分配给该控件的 AccessibleObject. AccessibleDefaultActi ...
- extjs4 分页工具栏pagingtoolbar的每页显示数据combobox下拉框
var itemsPerPage = 20; var combo; //创建数据源store Ext.define('recordStore', { extend : 'Ext.data.Store' ...
- A customized combobox with JQuery
要求实现一个轻量级的在客户端筛选的combobox,支持大数据量(超过1000个items),能快速检索内容,并支持数据的设置和活动等基本操作.在这之前尝试过使用Jquery UI的Autocompl ...
- easyui combobox 在datagrid中动态加载数据
场景:datagrid 中用编辑框修改数据,有一个列使用的combobox 在可编辑的时候需要动态绑定数据,这个数据是在根据其他条件可变的 思路:在每次开启编辑框的时候动态绑定数据, datagri ...
- wpf ComboBox的SelectionBoxItem相关依赖属性
以前没有注意SelectionBoxItem相关依赖属性,这几天看wpf源码 特意研究了一番 <Style x:Key="ComboBoxStyle1" TargetType ...
- ExtJS ComboBox 下拉列表详细用法
ExtJS ComboBox 下拉列表详细用法 标签: combobox 2015-06-14 23:23 5171人阅读 评论(2) 收藏 举报 分类: ExtJS(32) 目录(?)[+] ...
随机推荐
- docker 初探
2015-08-14 09:24:42 查看本地已经有的镜像: docker images 启动镜像实例(例centos), 并进入centos命令行提示符 (镜像的一个实例就叫container): ...
- 配置ubuntu虚拟机备忘
#1配置minicom sudo minicom -s sudo minicom -w #1.配置网络,嵌入机的ip地址 ifconfig eth0 10.5.52.202 #2.挂载文件,把虚拟主机 ...
- VS2010工程文件减肥
由于VS2010中新增加了sdf和ipch文件等浏览数据库来支持智能浏览感知编辑.显示类视图等,使得随便一个小工程就上百兆,很占用空间也不方便工程项目的打包备份.为了不使用数据库以减小VS2010中的 ...
- 算法手记 之 数据结构(并查集详解)(POJ1703)
<ACM/ICPC算法训练教程>读书笔记-这一次补上并查集的部分.将对并查集的思想进行详细阐述,并附上本人AC掉POJ1703的Code. 在一些有N个元素的集合应用问题中,通常会将每个元 ...
- MongoDB 3.0 新特性【转】
本文来自:http://www.open-open.com/lib/view/open1427078982824.html#_label3 更多信息见官网: http://docs.mongodb.o ...
- 【编程题目】在 O(1)时间内删除链表结点
60.在 O(1)时间内删除链表结点(链表.算法).题目:给定链表的头指针和一个结点指针,在 O(1)时间删除该结点.链表结点的定义如下:struct ListNode{int m_nKey;List ...
- 【python】判断字符串日期是否有效
来源: http://www.jb51.net/article/66014.htm http://www.runoob.com/python/att-time-strptime.html 用time模 ...
- pod install 慢
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...
- October 6th 2016 Week 41st Thursday
The outer world you see is a reflection of your inner self. 你拥有什么样的内心,你就会看到什么样的世界. And we eventually ...
- XMPP框架下微信项目总结(5)花名册获取(好友列表)
---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...