I created an algorithm for this specific case. For clearer understanding, I illustrated it as follows:
Click to see
I only inserted the necessary codes.
<Window x:Class="Ganj_Aseman.MessageWindow" x:Name="Message_Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Ganj_Aseman"
mc:Ignorable="d"
Loaded="MessageWindow_Loaded" AllowsTransparency="True" Background="Transparent" FontSize="13" Height="228" RenderTransformOrigin="0.5,0.5" ResizeMode="NoResize" ShowInTaskbar="False" Width="430" WindowStartupLocation="CenterOwner" WindowStyle="None">
<Window.RenderTransform>
<TransformGroup>
<RotateTransform/>
<ScaleTransform/>
</TransformGroup>
</Window.RenderTransform>
<Window.Resources>
<Storyboard x:Key="CloseMessageWindow" Storyboard.TargetName="Message_Window" Completed="CloseMessageWindow_Completed">
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].Angle" Duration="0:0:7" To="360"/>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[1].ScaleX" Duration="0:0:7" To="0"/>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[1].ScaleY" Duration="0:0:7" To="0"/>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:7.5" To="0"/>
</Storyboard>
</Window.Resources>
<Grid>
<Button Name="OKButton" GotFocus="OKButton_GotFocus" PreviewMouseLeftButtonDown="OKButton_PreviewMouseLeftButtonDown" Content="OK" HorizontalAlignment="Left" VerticalAlignment="Top" Height="34" Margin="177.5,180,0,0">
<Button.Effect>
<DropShadowEffect BlurRadius="3" ShadowDepth="0.1" Direction="-90" Color="#e9f1cc"/>
</Button.Effect>
<Button.Triggers>
<EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
<BeginStoryboard Storyboard="{StaticResource CloseMessageWindow}"/>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</Window>
Owner window:
private async void Add_Button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
await Task.Run(() =>
{
OleDbParameter Parameter = new OleDbParameter();
Parameter.OleDbType = OleDbType.Binary;
Parameter.ParameterName = "BookImage";
Dispatcher.Invoke(() =>
{
Parameter.Value = ImageToBytes((BitmapImage)BookImage.Source);
});
OleDbCommand OleDbCommandInsert = new OleDbCommand("Insert Into BookInfo(BookName,Authors,Publisher,[ISBN-13],[ISBN-10],Category,PublicationDate,BookLanguage,Length,[Type],Translators,Narrators,DeweyDecimalClassification,UniversalDecimalClassification,LibraryOfCongressClassification,BookImage,Price) Values(@BookName,@Authors,@Publisher,@ISBN13,@ISBN10,@Category,@PublicationDate,@BookLanguage,@Length,@Type,@Translators,@Narrators,@DeweyDecimalClassification,@UniversalDecimalClassification,@LibraryOfCongressClassification,@BookImage,@Price)", OleDbConnect);
Dispatcher.Invoke(() =>
{
OleDbCommandInsert.Parameters.AddWithValue("@BookName", BookName_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Authors", Authors_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Publisher", PublicationDate_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@ISBN13", ISBN13_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@ISBN10", ISBN10_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Category", Category_ComboBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@PublicationDate", PublicationDate_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@BookLanguage", Language_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Length", ushort.Parse(Length_TextBox.Text));
OleDbCommandInsert.Parameters.AddWithValue("@Type", Type_ComboBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Translators", Translators_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@Narrators", Narrators_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@DeweyDecimalClassification", DeweyDecimalClassification_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@UniversalDecimalClassification", UniversalDecimalClassification_TextBox.Text);
OleDbCommandInsert.Parameters.AddWithValue("@LibraryOfCongressClassification", LibraryOfCongressClassification_TextBox.Text);
OleDbCommandInsert.Parameters.Add(Parameter);
OleDbCommandInsert.Parameters.AddWithValue("@Price", Price_TextBox.Text);
});
OleDbConnect.Open();
OleDbCommandInsert.ExecuteScalar();
OleDbConnect.Close();
Dispatcher.Invoke(() =>
{
MessageWindow MW = new MessageWindow();
MW.Owner = this;
MW.Owner.IsEnabled = false;
MW.YesButton.Visibility = Visibility.Hidden;
MW.NoButton.Visibility = Visibility.Hidden;
MW.Image.Source = GetImageFromBytes(System.IO.File.ReadAllBytes(System.Windows.Forms.Application.StartupPath + @"\Images\Check.bin"));
switch (App.EnumLanguage)
{
case AllLanguage.English:
MW.MessageTextBlock.Text = "Information added successfully";
MW.OKButton.Content = "OK";
break;
default:
MW.MessageTextBlock.Text = "اطلاعات با موفقیت اضافه شد";
MW.OKButton.Content = "تایید";
break;
}
MW.Show();
});
});
}
Message window:
private void OKButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Owner.IsEnabled = true;
}
private void CloseMessageWindow_Completed(object sender, EventArgs e)
{
Close();
}
Result (I set the
Duration
property of the
Animation
to 7 seconds to better understand the result):
Click to see