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) 目录(?)[+] ...
随机推荐
- poj 1326
http://poj.org/problem?id=1326 一个模拟的水题 题意就是要你算飞行的英里数. F代表头等舱,为实际飞行的英里数的2倍. B为商务舱,为实际飞行的英里数的1.5倍. Y为经 ...
- Linux安装字体
用惯了Win7的字体,感觉雅黑看着很舒服,就动手在Linux安装下,简单描述下: 第一步:百度一下,找到微软雅黑字体(.ttf)下载 第二步:把下载的字体放到cd /usr/share/fonts/z ...
- 关闭window 8.1 的skydrive
gpedit.msc-->计算机配置-->管理模板-->windows组件 -->skydrive-->阻止使用skydrive执行文件存储
- HDU 4966 GGS-DDU(最小树形图)
n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...
- nyoj366_D的小L_字典序_全排列
D的小L 时间限制:4000 ms | 内存限制:65535 KB 难度:2 描述 一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给 ...
- 【python】time,datetime,string相互转换
来源:http://essen.iteye.com/blog/1452098 #把datetime转成字符串 def datetime_toString(dt): return dt.strftime ...
- LightOJ 1234 Harmonic Number
D - Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu S ...
- jquery-validation-1.13.1 自定义验证正则
/*** check Mobile***********************/ jQuery.validator.addMethod("isMobile", function( ...
- php Internal Server Error
Internal Server Error The server encountered an internal error or misconfiguration and was unable to ...
- 解决客户端访问https报错
现象: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at com.sun.net.ssl. ...