Hi
I am a beginner in C # WPF. I have two problems that I want to share with you so that you can help me
In one part of my application I have a textbox a button on my form.
On button click, I make a query on the database and I execute other tasks.
The execution time is a little long before the results are displayed.
So I would like to display the message "Please wait, loading" for the user during treatment. and also display a gif file (loading) next to the message.
I would like the message in a label next to my textbox and not in another window or dialog.
I read on the forums that i have to use threads but I don' t understand it properly.
I finally found a code that m 'solved the problem half.
public static void ForceUIToUpdate()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
{
frame.Continue = false;
return null;
}), null);
Dispatcher.PushFrame(frame);
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
this.pictureBoxLoading.Visibility = System.Windows.Visibility.Visible;
this.status.Content= "Please wait, loading";
ForceUIToUpdate();
// function for long treat
runCode();
md.Visibility = System.Windows.Visibility.Collapsed;
this.pictureBoxLoading.Visibility = System.Windows .Visibility .Collapsed ;
this.status.Content= "";
}My xaml code
<Grid x:Name="AddboxGrid" Grid.Row ="1" Background="#FFB6B6B6" Height="80" ><Grid Margin="0,1,0,0" Width="229" Background="#FFE8E8E8" HorizontalAlignment="Left" VerticalAlignment="Top" Height="79" ><TextBox x:Name="url_or_rss" Style="{StaticResource StandardPlaceholder }" HorizontalAlignment="Left" Height="23" TextWrapping="NoWrap" VerticalAlignment="Top" Width="219" BorderBrush="#FFB6B6B6" BorderThickness="1" Margin="4,7,0,0" Foreground="#FF3A3939"/><Button Content="Add" Style="{StaticResource btnStyle}" HorizontalAlignment="Left" Margin="180,41,0,0" VerticalAlignment="Top" Width="42" Click="Button_Click_4" Height="23" FontSize="12"/><Label Content="1" Name="Addbox" HorizontalAlignment="Left" Margin="39,39,0,0" VerticalAlignment="Top" Visibility="Collapsed"/><Label Content="" Name="status" HorizontalAlignment="Right" Margin="0,43,79,0" VerticalAlignment="Top" Width="130"/><WindowsFormsHost x:Name="pictureBoxLoading" Margin="-11,36,188,6" Width="20" Height="18" ><wf:PictureBox x:Name="picture" ImageLocation="E:\3.gif" Height="10" /></WindowsFormsHost></Grid>I found it easy and the result is what I wanted except that the GIF is no longer running, the image remains static.
But if I 'use image on other grid, it runs well.
then I wonder if the code that I found was the right solution for my problem.
If so how could I turn my gif (animated picture) during the processing of the transaction.
If not, what code should be used to get best Result.
Thanks for your help
AS