Advanced Distributed Systems module at HSLU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

103 lines
3.0 KiB

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace RobotClientWpf.Utilities
{
public static class UIAccessHelpers
{
public static void SetButtonState(ButtonBase button, bool enabled)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SetButtonState(button, enabled);
}));
}
else
{
button.IsEnabled = enabled;
}
}
public static void SetButtonContent(ButtonBase button, string content)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SetButtonContent(button, content);
}));
}
else
{
button.Content = content;
}
}
public static string GetTextboxText(TextBox textBox)
{
string text = String.Empty;
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
text = GetTextboxText(textBox);
})).Wait();
}
else
{
text = textBox.Text;
}
return text;
}
public static void SetTextboxState(TextBoxBase textBox, bool enabled)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SetTextboxState(textBox, enabled);
}));
}
else
{
textBox.IsEnabled = enabled;
}
}
public static void SetTextboxText(TextBox textBox, string text)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SetTextboxText(textBox, text);
}));
}
else
{
textBox.Text = text;
}
}
public static void SetTextblockTextAndForegroundColor(TextBlock textBlock, string text, Brush foregroundColor)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SetTextblockTextAndForegroundColor(textBlock, text, foregroundColor);
}));
}
else
{
textBlock.Text = text;
textBlock.Foreground = foregroundColor;
}
}
}
}