使用组合框项激活状态 [英] Activating states using combo box items

查看:62
本文介绍了使用组合框项激活状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Sketchflow(我是初学者)并正在为软件制作原型。我有一个我无法处理的问题。使用组合框项激活状态。我可以展开组合框并选择每个项目,右键单击并将其设置为
以激活状态,但是当我运行项目时它似乎不起作用。请快速回复! (我正在使用Blend 3)

I have just started using Sketchflow (i am a beginner) and am making a prototype for a software. I have a problem that i cannot handle. Activation of states using combo box items. I can expand the combo box and select each item, right click and set it to activate the state but it doesn't seem to work when i run the project. Please reply fast guys! (I am using Blend 3)

推荐答案

不幸的是,组合框吞下鼠标事件是出于内部目的,因此mousedown的默认触发器不起作用。

Unfortunately the combobox swallows the mouse events for its own internal purposes, so the default trigger of mousedown doesn't work.

 

你没有提到你是使用Silverlight还是WPF,但这里有一个可以用来完成的银色触发器你的目标。

You didn't mention if you are using Silverlight or WPF, but here is a silverlight trigger that can be used to accomplish your goals.

文件 - >新商品 - >触发,添加以下代码:

File -> New Item -> Trigger, add the following code:


using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace SilverlightPrototype1Screens
{
	public class ComboBoxItemSelectedTrigger : TriggerBase<ComboBox>
	{
		public static readonly DependencyProperty ComboBoxItemNameProperty = DependencyProperty.Register("ComboBoxItemName", typeof(string), typeof(ComboBoxItemSelectedTrigger), new PropertyMetadata(String.Empty));

		public string ComboBoxItemName
		{
			get { return (string)this.GetValue(ComboBoxItemNameProperty); }
			set { this.SetValue(ComboBoxItemNameProperty, value); }
		}

		protected override void OnAttached()
		{
			base.OnAttached();
			var comboBox = this.AssociatedObject;
			if(comboBox != null)
			{
				comboBox.SelectionChanged += selectionChanged;
			}
		}

		protected override void OnDetaching()
		{
			base.OnDetaching();
			var comboBox = this.AssociatedObject;
			if (comboBox != null)
			{
				comboBox.SelectionChanged -= selectionChanged;
			}
		}

		private void selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
		{
			if(e.AddedItems.Cast<ComboBoxItem>().Any(item => item.Name != null && item.Name == this.ComboBoxItemName))
			{
				this.InvokeActions(null);
			}
		}
	}
}


这篇关于使用组合框项激活状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆