Je vous propose d'utiliser la propriété Visibilité de cette partie de l'écran que vous souhaitez faire apparaître et d'utiliser un déclencheur pour le rendre Invisible ou Réduit à Visible à chaque fois que l'utilisateur tape ou sélectionne. Ou vous pouvez animer la propriété Opacité pour produire un effet d'évanouissement cool ;-) Je vais ajouter du code pour illustrer le point. EDIT: un temps BackgroundTask, comme les opérations de fichiers, peut être réalisé en utilisant un BackgroundWorker
<Window x:Class="VisibleOnTypingSpike.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Name="TypingSnooper"
Visibility="{Binding TypingSnooperVisibility}">
You are typing!</Label>
<Label>
<Label.Style>
<Style>
<Setter Property="Label.Opacity" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding HasListBoxNewSelection}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation From="0" To="1"
Duration="0:0:1"
Storyboard.TargetProperty="Opacity"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation From="1" To="0"
Duration="0:0:1"
Storyboard.TargetProperty="Opacity"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
You selected!
</Label>
</StackPanel>
<TextBox TextChanged="TextBox_TextChanged"></TextBox>
<ListBox Name="SimpleListBox"
SelectionChanged="SimpleListBox_SelectionChanged">
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
</ListBox>
</StackPanel>
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 =
DependencyProperty.Register("TypingSnooperVisibility",
typeof(Visibility),
typeof(Window1),
new UIPropertyMetadata(System.Windows.Visibility.Collapsed));
public bool HasListBoxNewSelection
{
get { return (bool)GetValue(HasListBoxNewSelectionProperty); }
set { SetValue(HasListBoxNewSelectionProperty, value); }
}
public static readonly DependencyProperty HasListBoxNewSelectionProperty =
DependencyProperty.Register("HasListBoxNewSelection",
typeof(bool),
typeof(Window1),
new UIPropertyMetadata(false));
public Window1()
{
InitializeComponent();
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;
}
}
}
aide ne marche pas toujours avec la question de filetage que j'ai peur, le problème est que la seule fonction par exemple de par exemple charger un document peut produire "stutter" dans l'interface, j'ai vraiment besoin de l'exécuter dans un thread séparé – Homde
J'ai ajouté le code de toute façon ;-) Des choses comme le chargement d'un document que vous pouvez accomplir en utilisant BackgroundWorker. J'ai inclus un lien vers msdn dans la réponse ci-dessus. WPF n'autorisera jamais deux parties de la même interface utilisateur à s'exécuter sur des threads séparés. Vous devez effectuer votre tâche fastidieuse en arrière-plan, puis informer l'interface utilisateur par un événement que les nouvelles données sont prêtes. – Dabblernl
Bien sûr que je le peux, je peux superposer des fenêtres les unes sur les autres, chacune en cours d'exécution de son propre fil et même être transparent. C'est un peu un hack mais ça marche. Je vois maintenant pourquoi un cadre ne pouvait pas fonctionner dans son propre fil – Homde