WPF 프로젝트가 있고 프로젝트 마법사가 스플래시 화면을 추가했습니다. 같은 시작 화면에서 진행률 막대 스타일 미터를 추가하고 싶습니다. 누군가이 일을하는 방법을 알고 있습니까?WPF SplashScreen with ProgressBar
3
A
답변
9
여기에 대한 나의 계획입니다. 내가 UI 스레드에서 실행되는 초기화 코드를 갖고 싶지 않고 일반적으로 내 App 클래스 (시작 화면이 아님)에 초기화 코드를 넣고 싶지는 않다.
기본적으로 볼을 굴리는 내 스플래시 화면에 App StartupUri
을 설정합니다.
스플래시 화면에서 응용 프로그램에 대한 대리자를 다시 호출합니다. 이것은 작업자 스레드에서 실행됩니다. 스플래시 화면에서 나는 EndInvoke
을 처리하고 창을 닫습니다.
응용 프로그램 초기화 대리인에서 작업을 수행하고 끝에 일반 기본 창을 만들고 엽니 다. 작업로드 중에 슬래시를 사용하여 진행 상황을 업데이트 할 수있는 메서드가 있습니다.
좋습니다, 코드는 매우 짧으며 (이 모든 영향을받지 않는) 기본 창 코드는 포함되어 있지 않지만 익명의 대리인과 함께 오리와 다이빙을하므로주의 깊게 읽고 이상적으로 사용하십시오 디버거. 여기
뒤에<Application x:Class="SplashScreenDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Splash.xaml">
<Application.Resources>
</Application.Resources>
</Application>
응용 프로그램 코드 ...
internal delegate void Invoker();
public partial class App : Application
{
public App()
{
ApplicationInitialize = _applicationInitialize;
}
public static new App Current
{
get { return Application.Current as App; }
}
internal delegate void ApplicationInitializeDelegate(Splash splashWindow);
internal ApplicationInitializeDelegate ApplicationInitialize;
private void _applicationInitialize(Splash splashWindow)
{
// fake workload, but with progress updates.
Thread.Sleep(500);
splashWindow.SetProgress(0.2);
Thread.Sleep(500);
splashWindow.SetProgress(0.4);
Thread.Sleep(500);
splashWindow.SetProgress(0.6);
Thread.Sleep(500);
splashWindow.SetProgress(0.8);
Thread.Sleep(500);
splashWindow.SetProgress(1);
// Create the main window, but on the UI thread.
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate
{
MainWindow = new Window1();
MainWindow.Show();
});
}
}
시작 xaml
(실제로, 여기 너무 흥미로운 아무것도 ...)
<Window x:Class="SplashScreenDemo.Splash"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Splash" Height="300" Width="300">
<Grid>
<TextBlock Height="21" Margin="91,61,108,0" VerticalAlignment="Top">Splash Screen</TextBlock>
<ProgressBar Name="progBar" Margin="22,122,16,109" Minimum="0" Maximum="1"/>
</Grid>
</Window>
.... 코드입니다
스플래시 코드 숨김 ...
public partial class Splash : Window
{
public Splash()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Splash_Loaded);
}
void Splash_Loaded(object sender, RoutedEventArgs e)
{
IAsyncResult result = null;
// This is an anonymous delegate that will be called when the initialization has COMPLETED
AsyncCallback initCompleted = delegate(IAsyncResult ar)
{
App.Current.ApplicationInitialize.EndInvoke(result);
// Ensure we call close on the UI Thread.
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate { Close(); });
};
// This starts the initialization process on the Application
result = App.Current.ApplicationInitialize.BeginInvoke(this, initCompleted, null);
}
public void SetProgress(double progress)
{
// Ensure we update on the UI Thread.
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate { progBar.Value = progress; });
}
}
작업이 작업자 스레드에서 수행됨에 따라 진행률 표시 줄이 잘 업데이트되고 시작 화면에있는 애니메이션으로 인해 엔터테인먼트 롤링이 유지됩니다.
관련 문제
- 1. WPF SplashScreen with UserControl
- 2. WPF DataGrid Progressbar with Text
- 3. 안드로이드 이미지로드 progressbar with
- 4. C# List with ProgressBar
- 5. 업데이트 progressbar with android
- 6. WPF 변경 progressbar 전경색
- 7. WPF 무시 ProgressBar 스타일
- 8. wxPython custom SplashScreen with progress gauge
- 9. .NET 3.5 Windows Forms에서 WPF SplashScreen 사용
- 10. WPF 응용 프로그램 창이 SplashScreen 위에 나타납니다
- 11. WPF 리소스가 SplashScreen 구현 후로드되지 않습니다.
- 12. 웹 서비스 호출을위한 WPF ProgressBar
- 13. 다른 클래스의 WPF - progressbar 업데이트
- 14. Java SplashScreen
- 15. Silverlight ProgressBar with custom image 벽돌
- 16. 별도의 스레드에 WPF ProgressBar 창 표시
- 17. 이 간단한 WPF 응용 프로그램에서 progressbar 구현
- 18. WPF 용 INotifyPropertyChanged를 구현하는 방법 ProgressBar
- 19. 업데이트 progressbar + backgroundworker가있는 clipboard.getimage() - WPF C#
- 20. 값 데이터 바인딩을 사용하는 WPF ProgressBar
- 21. 특정 값을 가진 ProgressBar 콘텐츠 WPF 애니메이션
- 22. 왜 WPF ProgressBar PART_Indicator가 불투명도를 추가하나요?
- 23. WPF 템플릿에서 부드럽게 애니메이션 된 ProgressBar
- 24. WPF with XAML의 스타일 진행 막대
- 25. WPF TextBox.Text with MultiBinding
- 26. WPF with CurrentItem 바인딩
- 27. WPF DataGrid with Bands
- 28. WPF TextBox with ViewModel
- 29. WPF ComboboxItems with button
- 30. WPF datagrid with datatable
그래서 초기화하는 모든 것이 전역 변수에 저장됩니까? –
(Invoker)가 나를 위해 작동하지 않고 "새로운 액션 (delegate()"으로 대체했습니다 –
밑줄로 시작하는 메소드 선언 ... 정말요? – Slugart