Pergunta

alterar o texto de uma etiqueta (ou sofisticadamente podemos dizer uma barra de progresso baseado em texto). em winforms você só Invalidate / atualizar.

Mas como fazer isso no WPF sem usar threads em segundo plano. ???

Foi útil?

Solução

    public static class ExtensionMethods
{

   private static Action EmptyDelegate = delegate() { };


   public static void Refresh(this UIElement uiElement)
   {
      uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
   }
}

private void LoopingMethod()
{
   for (int i = 0; i < 10; i++)
   {
      label1.Content = i.ToString();
      label1.Refresh();
      Thread.Sleep(500);
   }
}

Referência: http: // geekswithblogs .net / NewThingsILearned / Arquivo / 2008/08/25 / refresh - update-wpf-controls.aspx

Outras dicas

Talvez você deve ler mais sobre o assunto de Ligações . .

Basicamente, as ligações irão gerenciar isso para você ..

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top