如何切换多个扩展器但具有智能。 [英] How to toggle more than one expander but with intelligence.

查看:74
本文介绍了如何切换多个扩展器但具有智能。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下帖子:  http://social.expression.microsoft.com/Forums/en-US/blend/thread/70f77ef9-7f48-4922-a7a6-83c24dc014c6/   I
分配了密钥F5,F6和F7切换我的应用程序的顶部,左侧和右侧的扩展器面板,这是一种享受。

Following on from this thread: http://social.expression.microsoft.com/Forums/en-US/blend/thread/70f77ef9-7f48-4922-a7a6-83c24dc014c6/ I have assigned the keys F5, F6 and F7 to toggle the expander panels for top, left and right of my application which works a treat.

我认为下一步将是有一个快捷方式来切换所有的扩展器,所以我在每个扩展器上设置另一个触发器并分配F8来切换它们 - 再次起作用。

I thought the next step would be to have a shortcut to toggle all the expanders, so I set up another trigger on each expander and assigned F8 to toggle them all - again works a treat.

但是,我现在有一个问题。

But, I now have an issue.

如果顶部和左侧打开,右侧关闭,如果按F8,它只需按预期切换它们。但是从UI的角度来看,无论当前状态如何设置,我都希望它们能够隐藏或显示在一起。

If top and left are open, and right is closed, if you press F8 it simply toggles them all as expected. But from a UI point of view, I'd like them all to either hide or show together no matter what their current state is set to.

所以为了简化,当你按下F8时第一次,我希望它隐藏所有面板,然后再次显示它们,无论它们处于什么状态。

So to simplify, when you press F8 for the first time, I want it to hide all the panels, then again, to show them all no matter what state they are in.

有人能指出我正确的方向吗?

Can anyone point me in the right direction please?

推荐答案

这是让你入门的东西。它基于TargetedTriggerAction Chuck在你链接的帖子中给你。显然,您必须根据自己的特殊需求进行更改。此操作将展开或折叠所有扩展程序,
是关联面板的直接子项。

Here's something to get you started. It's based off the TargetedTriggerAction Chuck gave you in the post to which you linked. Obviously you'll have to change this to suit your own particular needs. This action will expand or collapse all the Expanders that are immediate children of the associated panel.

显然论坛讨厌我的使用"小组" (括号内的)。它应该是一个TriggerAction,其泛型的Panel参数。请忽略"面板"的所有其他随机实例。和"/ panel"分散在各处。 : - )

Apparently the forum hates my use of "Panel" (in brackets). It should be a TriggerAction with a Panel argument to its generic. Please ignore all the other random instance of "panel" and "/panel" scattered throughout. :-)

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

namespace SilverlightApplication34
{
    public class ToggleAllExpandersAction : TriggerAction<panel><panel><panel>    {
        private bool ShouldExpand { get; set; }

        public ToggleAllExpandersAction()
        {
            // This sets the initial state of the action.
            // The first time the action is invoked, it will
            // expand all expanders within the current panel.
            this.ShouldExpand = true;
        }

        protected override void Invoke(object parameter)
        {
            foreach (var child in this.AssociatedObject.Children)
            {
                Expander expander = child as Expander;
                if (expander != null)
                {
                    expander.IsExpanded = this.ShouldExpand;
                }
            }

            // Toggle the state of the action so the next invocation
            // has the oppoosite effect.
            this.ShouldExpand = !this.ShouldExpand;
        }
    }
}</panel></panel></panel>




这是我的XAML:

<grid background="White" x:name="LayoutRoot">
	
		<ei:keytrigger key="F8">
			<local:toggleallexpandersaction></local:toggleallexpandersaction>
		</ei:keytrigger>
	
	
	<toolkit:expander header="Expander" horizontalalignment="Left" verticalalignment="Top">
		<grid background="#FFE5E5E5"></grid>
	</toolkit:expander>
	<toolkit:expander header="Expander" horizontalalignment="Left" margin="164,0,0,0" verticalalignment="Top">
		<grid background="#FFE5E5E5">
			<grid.columndefinitions>
				<columndefinition width="0.43*">
				<columndefinition width="0.465*">
				<columndefinition width="0.105*">
			</columndefinition></columndefinition></columndefinition></grid.columndefinitions>
		</grid>
	</toolkit:expander>
	<toolkit:expander d:layoutoverrides="Width" header="Expander" margin="305,0,256,0" verticalalignment="Top">
		<grid background="#FFE5E5E5"></grid>
	</toolkit:expander>
</grid>

希望有所帮助。


这篇关于如何切换多个扩展器但具有智能。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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