참고 : XBAP 브라우저 앱에서는이 기능을 사용하지 않았지만 WPF 앱에서 아무 문제없이 작동합니다. 필요할 때 DispatcherTimer를 사용하여 모래 시계를 표시하고이 코드를 정적 클래스로 추상화합니다.
public static class UiServices
{
/// <summary>
/// A value indicating whether the UI is currently busy
/// </summary>
private static bool IsBusy;
/// <summary>
/// Sets the busystate as busy.
/// </summary>
public static void SetBusyState()
{
SetBusyState(true);
}
/// <summary>
/// Sets the busystate to busy or not busy.
/// </summary>
/// <param name="busy">if set to <c>true</c> the application is now busy.</param>
private static void SetBusyState(bool busy)
{
if (busy != IsBusy)
{
IsBusy = busy;
Mouse.OverrideCursor = busy ? Cursors.Wait : null;
if (IsBusy)
{
new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher);
}
}
}
/// <summary>
/// Handles the Tick event of the dispatcherTimer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private static void dispatcherTimer_Tick(object sender, EventArgs e)
{
var dispatcherTimer = sender as DispatcherTimer;
if (dispatcherTimer != null)
{
SetBusyState(false);
dispatcherTimer.Stop();
}
}
}
이처럼 사용합니다 :
void DoSomething()
{
UiServices.SetBusyState();
// Do your thing
}
희망이 도움이!
모든 UI 작업이 UI 스레드에서 발생해야하므로 더 좋은 방법은 없습니다. 임씨는 당신의 진술에 대해 걱정하고 있습니다. '몇 페이지에서 모든 컨트롤이 사용자가 선택한 항목에 따라 동적으로 생성됩니다.' 이는 적절한 패턴 (MVVM)을 적용하지 않았고 이러한 모든 UI 요소를 코드에 작성하는 것처럼 들리지만 잘못된 것이므로 이러한 성능 문제가 발생할 수 있습니다. 몇 가지 코드를 보여 주면 아마 우리가 그걸 도와 줄 수 있습니다. –
불행히도 나는 코드를 게시 할 수 없지만 기본적으로 페이지에는 텍스트 상자, 목록 상자, 드롭 다운, 사용자 컨트롤 등이 포함될 수 있으므로 사용자가 필요로하는 것에 따라 페이지에 표시하거나 숨길 수 있습니다. 맞춤 설정할 수 있습니다. 시간이 걸릴 수있는 이러한 컨트롤의로드입니다. 그것은 MVVM이지만 코드를 물려 받았기 때문에 아마도 다른 것도있을 수 있습니다. 어쨌든 건배는 그걸보아야합니다. – knappster
@knappster HighCode가 말한 것과 마찬가지로 사용자 지정된 컨트롤을 "로드"할 필요가 없습니다. 이를 달성하는 데 사용할 수있는 몇 가지 기술이 있습니다. DataTriggers를 사용하여 속성 값을 기반으로 특정 컨트롤을 표시하거나 숨길 수 있습니다. 사용자 정의 컨트롤을 UserControls로 추상화하고 DataTemplate (모든 DataTemplateSelector)을 사용하여 사용되는 UserControl을 제어 할 수 있습니다. 어쨌든 나는 당신의 진짜 문제 (아래 마우스 마우스)에 대한 대답을하려고 노력할 것입니다. – failedprogramming