I actually try to update the MainWindow UI from a RefreshEvent in a external class.
I tried out the following, but the UI doesnt refresh.
System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate
{
foreach (OPCItem o in ((MainWindow)System.Windows.Application.Current.MainWindow).dgItems.Items)
{
if (o.ItemID == arg.items[i].OpcIDef.ItemID)
{
o.Value = Item.Value;
o.DateTime = Item.DateTime;
o.Quality = Item.Quality;
((MainWindow)System.Windows.Application.Current.MainWindow).dgItems.Items.Refresh();
}
}
}));
Calling ((MainWindow)System.Windows.Application.Current.MainWindow).UpdateLayout()
should do the trick
to be sure your ui is refreshed you should use Dispatcher
public static class UiRefresh
{
private static Action EmptyDelegate = delegate () { };
public static void Refresh(this UIElement uiElement)
{
uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
}
}
then yourElement.Refresh() will do the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With