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) 目录(?)[+] ...
随机推荐
- oracle,mybatis主键自增长
<insert id="insert" parameterType="resource"> <selectKey resultType=&qu ...
- irc操作小记
IRC客户端 HexChat 跨平台支持,目前正在Windows上使用,暂无不满意的地方 polari 支持的命令太少了,功能有限. Empathy 重量级,支持各种消息协议 weechat/irss ...
- [Android] how to get facebook profile
Bundle params = new Bundle(); params.putString("fields", "id,email,gender,cover,pictu ...
- 创建一个没有边框的并添加自定义文字的UISegmentedControl
//个性推荐 歌单 主播电台 排行榜 NSArray* promoteArray=@[@"个性推荐",@"歌单",@"主播电台",@&quo ...
- C++基础(纯虚函数与抽象类)
C++基础之纯虚函数与抽象类 引言 纯虚函数在C++编程中的地位很重要,其关联到了设计模式中"接口"的概念. 语法 纯虚函数的语法: 1. 将成员函数声明为virtual 2. ...
- 初次使用 VUX
1. 因为以前没用过vux ,所以还是比较不熟练: 2.项目部署是根据git上的源码改的: 开始:将git上的项目下载或者clone到本地: 001:安装nodejs--> 002:npm in ...
- IOS- 单例
单例模式的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 1.单例模式的要点: 显然单例模式的要点有三个:一是某个类只能有一个实例: ...
- August 10th, 2016, Week 33rd, Wednesday
The degree of loving is measured by the degree of giving. 爱的深浅是用给与的多少来衡量的. Some say that if you love ...
- C#索引器一
索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 ...
- 数据库TSQL语句
一.创建数据库create database test3;二.删除数据库drop database test3;三.如何创建表create(创建) table(表) test(表名)(此处写列 var ...