0

悲しいことに、stackoverflow に関するこの問題についての質問は 1 つもありません。少なくとも、検索中に出くわしたものはありません。

とにかく、私が話しているプログラムが構築されるとき。表示される最初のウィンドウはログインです。ユーザーが正しいログイン情報を入力すると、メイン ウィンドウが表示されます。ただし、メイン ウィンドウには、インターネットから収集された大量の情報があります。

これにより、下の図 [1] に示すように、ある程度の時間、メイン ウィンドウが透明なままになります。インターネットから収集された情報は、いくつかの xml と MySQL データベースからのデータで構成されています。

次のような Window_Loaded イベントがあります。

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        method1();
        method2(1);
        method3();
        .
        .
        .
        //method6();
    }

したがって、明らかに、特定のメソッドをキャンセルしてこのイベントを短時間で終了すると、ウィンドウは通常の状態になる前に透明なままになり、小さくなります。

ただし、私がやりたいことは、ウィンドウを正常にロードしてから、コンテンツがロードされていることをユーザーに通知するためのロード インジケーターを表示することです。

ps mahapps.metro コントロールを使用しています。

前もって感謝します

4

2 に答える 2

1

これは、UI スレッドでブロック コードを実行しているため、ウィンドウを再描画する機会がないために発生します。
そのすべてをバックグラウンド スレッドで行う必要があります。

于 2012-09-06T13:37:51.980 に答える
0

これを試して

MainWindow とコード。

<Window x:Class="SplashScreenWithStatus.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="600" Width="800" Loaded="Window_Loaded">
    <Grid>

    </Grid>
</Window>



 public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            // Setting the status to show the application is still loading data
            Splash.Loading("Connecting...");
            // Set to sleep to simulate long running process
            Thread.Sleep(1500);
            Splash.Loading("Retrieving....");
            Thread.Sleep(1500);
            Splash.Loading("Success....");
            Thread.Sleep(1500);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Splash.EndDisplay();
        }
    }

スプラッシュスクリーンとコード

public partial class Splash : Window { private static Splash スプラッシュ = new Splash();

    // To refresh the UI immediately
    private delegate void RefreshDelegate();
    private static void Refresh(DependencyObject obj)
    {
        obj.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render,
            (RefreshDelegate)delegate { });
    }

    public Splash()
    {
        InitializeComponent();
    }

    public static void BeginDisplay()
    {
        splash.Show();
    }

    public static void EndDisplay()
    {
        splash.Close();
    }

    public static void Loading(string test)
    {
        splash.statuslbl.Content = test;
        Refresh(splash.statuslbl);
    }

    }

アプリ クラスの xaml とコード

<Application x:Class="SplashScreenWithStatus.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml" Startup="Application_Startup">
    <Application.Resources>

    </Application.Resources>
</Application>

 public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Splash.BeginDisplay();
        }
    }
于 2012-09-06T14:12:35.533 に答える