UI Automation-MultipleViewPattern

本文介绍了MultipleViewPattern控件模式的应用,该模式允许控件提供多种视图表示形式并能在不同视图间切换。文章通过示例展示了如何使用GetViewName获取视图名称和SetCurrentView设置当前视图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MultipleViewPattern控件模式用于支持控件,控件提供了同一组信息或子控件的多个表示形式,并且可以在这些表示形式之间进行切换。常用两种方法,GetViewName用来检索特定于控件的视图的名称,还有SetCurrentView,用来设置当前的特定于控件的视图。

示例:

        public static void TestMultipleViewpattern()

        {

            Process adressbook = Process.Start(@"C:/Program Files/Outlook Express/wab.exe");

            Thread.Sleep(2000);

 

            //Get main window   "Address Book - Main Identity"

 

            AutomationElement addresswindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Address Book - Main Identity"));

            Thread.Sleep(2000);

 

            AutomationElement list = Utility.UIA.FindAutomationElement.ByAutomationID(addresswindow, "9001",true);

            MultipleViewPattern listpattern = Utility.UIA.ControlPattern.MultipleViewpattern.GetMultipleViewPattern(list);

            if (listpattern.Current.CurrentView != 3)

            {

                //get view menu item

                AutomationElement view = Utility.UIA.FindAutomationElement.ByName(addresswindow, "View", false);

                ExpandCollapsePattern viewpattern = Utility.UIA.ControlPattern.ExpandCollapsepattern.GetExpandCollapsePattern(view);

                viewpattern.Expand();

                Thread.Sleep(2000);

 

                //get list menu item

                AutomationElement listitem = Utility.UIA.FindAutomationElement.ByName(addresswindow, "List", false);

                InvokePattern listpattern1 = Utility.UIA.ControlPattern.Invokepattern.GetInvokePattern(listitem);

                listpattern1.Invoke();

 

            }

 

 

        }

 

public static MultipleViewPattern GetMultipleViewPattern(AutomationElement element)

        {

            object currentPattern;

            if (!element.TryGetCurrentPattern(MultipleViewPattern.Pattern, out currentPattern))

            {

                throw new Exception(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the DockPattern.",

                    element.Current.AutomationId, element.Current.Name));

            }

            return currentPattern as MultipleViewPattern;

        }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值