<Window x:Class="Wpf_Task.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525"
Height="350"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Storyboard x:Key="OnLoaded1"
RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="0"
Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:1"
Value="360" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource OnLoaded1}" />
</EventTrigger>
</Window.Triggers>
<Grid>
<Button x:Name="executeButton"
Width="75"
Margin="0,216,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Click="Button_Click"
Content="Выполнить"
TextOptions.TextFormattingMode="Display" />
<Rectangle x:Name="border"
Width="100"
Height="100"
Margin="208,57,208,161"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFD1BD69" />
<GradientStop Offset="1" Color="#FFFFF5C9" />
</LinearGradientBrush>
</Rectangle.Fill>
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<TextBlock x:Name="_result"
Margin="0,187,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Text="..."
TextOptions.TextFormattingMode="Display"
TextWrapping="Wrap" />
</Grid>
</Window>
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace Wpf_Task
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
executeButton.IsEnabled = false;
Task<int>.Factory.StartNew(() =>
{
return Auth.Login();
})
.ContinueWith(task => //Выполнить код в основном потоке (TaskScheduler.FromCurrentSynchronizationContext())
{
executeButton.IsEnabled = true;
_result.Text = task.Result.ToString();
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}
public static class Auth
{
private static int _counter;
public static int Login()
{
Thread.Sleep(1000);
return ++_counter;
}
}
}