大佬教程收集整理的这篇文章主要介绍了Silverlight:Combobox中的默认值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<local:ExtendedComboBox Itemssource="{Binding ...whatever...}" NotSELEctedText="SELEct item..." />
此外,这是带有此控件的test page.我认为第二个组合框就是你所需要的.
这个类的完整代码:
[TemplateVisualState(Name = ExtendedComboBox.StateNormal,GroupName = ExtendedComboBox.GroupItemssourcE)] [TemplateVisualState(Name = ExtendedComboBox.StateNotSELEcted,GroupName = ExtendedComboBox.GroupItemssourcE)] [TemplateVisualState(Name = ExtendedComboBox.StateEmpty,GroupName = ExtendedComboBox.GroupItemssourcE)] public class ExtendedComboBox : ComboBox { public const String GroupItemssource = "ItemssourceStates"; public const String StateNormal = "Normal"; public const String StateNotSELEcted = "NotSELEcted"; public const String StateEmpty = "Empty"; private ContentPresenter SELEctedContent; public ExtendedComboBox() { this.DefaultStyleKey = typeof(ComboBox); } public override void OnApplyTemplate() { base.onApplyTemplate(); this.SELEctedContent = this.GetTemplateChild("ContentPresenter") as ContentPresenter; // This event can change the NotSELEcted state this.SELEctionChanged += (s,E) => this.SetTextIfEmpty(); // Set a state at start this.SetTextIfEmpty(); } // This method can change the Empty state protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs E) { base.onItemsChanged(E); this.SetTextIfEmpty(); } /// <sumMary> /// Text if the SELEctedItem property is null. /// </sumMary> public String NotSELEctedText { get { return (String)GetValue(NotSELEctedTextProperty); } set { SETVALue(NotSELEctedTextProperty,value); } } public static readonly DependencyProperty NotSELEctedTextProperty = DependencyProperty.Register("NotSELEctedText",typeof(String),typeof(ExtendedComboBox),new PropertyMetadata(" ")); /// <sumMary> /// Text if there are no items in the ComboBox at all. /// </sumMary> public String EmptyText { get { return (String)GetValue(EmptyTextProperty); } set { SETVALue(EmptyTextProperty,value); } } public static readonly DependencyProperty EmptyTextProperty = DependencyProperty.Register("EmptyText",new PropertyMetadata(null)); /// <sumMary> /// Changes the state of this control and updates the displayed text. /// </sumMary> protected void SetTextIfEmpty() { if (this.SELEctedContent == null || !(this.SELEctedContent.Content is TextBlock)) return; var text = this.SELEctedContent.Content as TextBlock; if (this.SELEctedItem == null && this.Items != null && this.Items.Count > 0) { text.Text = this.NotSELEctedText; VisualStateManager.GoToState(this,ExtendedComboBox.StateNotSELEcted,truE); } else if (this.SELEctedItem == null) { text.Text = this.EmptyText ?? this.NotSELEctedText; VisualStateManager.GoToState(this,ExtendedComboBox.StateEmpty,truE); } else VisualStateManager.GoToState(this,ExtendedComboBox.StateNormal,truE); } }
以上是大佬教程为你收集整理的Silverlight:Combobox中的默认值全部内容,希望文章能够帮你解决Silverlight:Combobox中的默认值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。