I have an application where when a person types or selects a listbox there's a portion of the screen that dynamically updates to a new view.

The problem is since WPF runs everything in a single thread the displaying of the view can interfer with typing or navigating making the app less responsive. What i'd like to do is run the view portion in a different thread.

My first thought was to use a window running on a different thread, but more than being something of a hack there's the problem of the window losing focus and being placed behind the mainwindow when the mainwindow is clicked. I could make it topmost but I also need to place other windows in front of it.

So what's the best way to achieve this, can I place the view in a frame and run it in a different thread?

No correct solution


You can load / generate the data in a backround thread and then update the UI using Dispatcher.BeginInvoke.

I would propose you use the Visibility property of this piece of the screen that you want to make appear and use a trigger to set it from Invisible or Collapsed to Visible whenever the user types or selecs. Or you can animate the Opacity property to produce a cool fading effect ;-) I will add some code to illustrate the point. EDIT: a time consuming backgroundtask, like File operations, can be accomplished using a BackgroundWorker

<Window x:Class="VisibleOnTypingSpike.Window1"
Title="Window1" Height="300" Width="300">
    <StackPanel Orientation="Horizontal">
        <Label Name="TypingSnooper"
               Visibility="{Binding TypingSnooperVisibility}">
            You are typing!</Label>
                    <Setter Property="Label.Opacity" Value="0"/>
                        <DataTrigger Binding="{Binding HasListBoxNewSelection}" Value="True">
                                <BeginStoryboard >
                                        <DoubleAnimation From="0" To="1"
                                <BeginStoryboard >
                                        <DoubleAnimation From="1" To="0"
            You selected!
    <TextBox TextChanged="TextBox_TextChanged"></TextBox>
    <ListBox Name="SimpleListBox"

    using System.Windows;
    using System.Windows.Controls;

namespace VisibleOnTypingSpike
    public partial class Window1 : Window
        public Visibility TypingSnooperVisibility
            get { return (Visibility)GetValue(TypingSnooperVisibilityProperty); }
            set { SetValue(TypingSnooperVisibilityProperty, value); }

        public static readonly DependencyProperty TypingSnooperVisibilityProperty =
                                        new UIPropertyMetadata(System.Windows.Visibility.Collapsed));

        public bool HasListBoxNewSelection
            get { return (bool)GetValue(HasListBoxNewSelectionProperty); }
            set { SetValue(HasListBoxNewSelectionProperty, value); }

        public static readonly DependencyProperty HasListBoxNewSelectionProperty =
                                        new UIPropertyMetadata(false));

        public Window1()
            DataContext = this;

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
            var textbox = (TextBox) sender;
            if (textbox.Text.Length > 0) TypingSnooperVisibility = Visibility.Visible;
            else TypingSnooperVisibility = Visibility.Hidden;

        private void SimpleListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            HasListBoxNewSelection = true;
            HasListBoxNewSelection = false;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow