Пример #1
0
        public void MakeAnnouncement(string message, bool polite = false)
        {
#if NET47
            string previousAccessibleLabel = Label;

            var announcementResetTimer = new DispatcherTimer();
            announcementResetTimer.Interval = new TimeSpan(0, 0, 5);
            announcementResetTimer.Tick    += (sender, args) => {
                element?.Dispatcher.BeginInvoke((Action)(() => {
                    AutomationProperties.SetLiveSetting(element, AutomationLiveSetting.Off);
                    Label = previousAccessibleLabel;
                }), DispatcherPriority.Normal);

                announcementResetTimer.Stop();
            };

            element.Dispatcher.BeginInvoke((Action)(() => {
                AutomationProperties.SetLiveSetting(element, polite ? AutomationLiveSetting.Polite : AutomationLiveSetting.Assertive);

                Label = message;
                var peer = FrameworkElementAutomationPeer.FromElement(element);
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);

                    // HACK: Giving some time to announce the message
                    announcementResetTimer.Start();
                }
            }), DispatcherPriority.Normal);
#else
            return;
#endif
        }
Пример #2
0
        public void SetAccessibilityLiveRegion(TFrameworkElement view, string liveRegion)
        {
            var liveSetting = AutomationLiveSetting.Off;

            switch (liveRegion)
            {
            case "polite":
                liveSetting = AutomationLiveSetting.Polite;
                break;

            case "assertive":
                liveSetting = AutomationLiveSetting.Assertive;
                break;
            }

            AutomationProperties.SetLiveSetting(view, liveSetting);
        }