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) 目录(?)[+] ...
随机推荐
- 77 找出最大连续自然数个数[Longest Consecutive Sequence in an Unsorted Array]
[本文链接] http://www.cnblogs.com/hellogiser/p/Longest-Consecutive-Sequence-in-an-Unsorted-Array.html [题 ...
- 和我一起学python,控制语句 (life is short ,we need python)
控制语句 if/elif/else if语句和一般编程语言一样,条件为true 执行 如: if true : print 'true' <----if.else下对齐,要使用相 ...
- Divide and Conquer:Cable Master(POJ 1064)
缆绳大师 题目大意,把若干线段分成K份,求最大能分多长 二分法模型,C(x)就是题干的意思,在while那里做下文章就可以了,因为这个题目没有要求长度是整数,所以我们要不断二分才行,一般50-100次 ...
- codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n, r, avg.然后有 n 行,每行有两个数:第 i 行有 ...
- LINUX查看系统日志
cat tail -f 日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安 ...
- SQL Server order by语句学习回顾
主要学习: 1.以指定的次序返回查询结果 2.按多个字段排序 3.按字串排序 4.处理排序空值 5.根据数据项的键排序 具体实例1---以指定的次序返回查询结果 n使用ORDER BY子句可以对结果集 ...
- 如何将Js代码封装成Jquery插件
很多相同的Jquery代码会在很多页面使用,每次都复制粘贴太麻烦了,不如封装成一个Jquery插件就方便了,至于影响网页的速度不,我就没有测试了哈. 代码如下 这是一个自定闪烁打印文字的Jquery特 ...
- 零基础十分钟学会用git在coding.net上传(pull)和push
---恢复内容开始--- 对于入门者来说,特别是刚刚接触计算机的人来说,模仿是最快的学习方式了,先能够会使用(对于初学者来说,这种使用新事物的感觉很能爽的)至于原理,以后再说.下面先让初学者快速的学会 ...
- 用Mysqlbinlog备份BinLog文件
默认情况下, mysqlbinlog读取二进制文件[BinLog]并以文本的方式呈现[text format].mysqlbinlog可以直接地从本地读取Log,也可以读取远程的Log[--read- ...
- java 设置允许ajax XMLHttpRequest 请求跨域访问
怎样才能算跨域?协议,域名,端口都必须相同,才算在同一个域. 方案1: 使用XMLHttpRequest... 异步请求不能跨域访问,除非要访问的网页响应头信息设置为允许跨域访问. 将网页设置为允许 ...