Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

[C# WPF] Dispatcher.Invoke(), Dispatcher.BeginInvoke() make Windows frezze

7 năm trước 3.153 lượt xem 3 bình luận 7 năm trước

Em có 1 picturebox như sau

 

Em đc nghe là CheckForIllgalCrossThreads = false; không dùng được trong WPF nên em lên Stack Overflow thì dùng 2 cái này

 

 Nhưng dùng như thế này thì Window (WPF UI)  bị đơ, 9 giây sau thì nó lại bình thường.

Vậy em muốn làm hiệu ứng Fade In thì phải dùng Method nào ạ.

 

 

 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 7 năm trước
(XAML)
<Window x:Class="Osu_Cancer.MainWindow"
        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:Osu_Cancer"
        mc:Ignorable="d"
        AllowsTransparency="True"
        WindowStyle="None"
        Background="Transparent"
        Loaded="Window_Loaded"
        Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen" WindowState="Maximized" ResizeMode="NoResize">
           
    <Grid>
        <Image x:Name="imgOsuLogo" Stretch="Uniform" Margin="205" Source="{Binding Logo}"></Image>
    </Grid>
</Window>
------------------------------------------------------------------------------------------------
(C#)
 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            imgOsuLogo.Opacity = 0;
        }

        private void FadeInLogo()
        {
            imgOsuLogo.Opacity = 0;
            
            for (int i = 0; i < 9; i++)
            {
                imgOsuLogo.Opacity += 0.1;
                Thread.Sleep(1000);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
Task t = new Task(()=>{
 Dispatcher.BeginInvoke(DispatcherPriority.Normal, new AVoidDelegate(FadeInLogo));
});
           t.Start();
        }
    }
    public delegate void AVoidDelegate();
}

 

C# learner đã bình luận 7 năm trước

Mà ko đc dùng class DoubleAnimation, em muốn tự làm animation chứ không dùng hàm hỗ trợ

Câu hỏi mới nhất