モーダル動作を持つカスタムポップアップを作成したいWPFアプリケーションがあります。「DoEvents」に相当するものを使用してソリューションをハックすることができましたが、これを行うためのより良い方法はありますか?これが私が現在持っているものです:
private void ShowModalHost(FrameworkElement element)
{
//Create new modal host
var host = new ModalHost(element);
//Lock out UI with blur
WindowSurface.Effect = new BlurEffect();
ModalSurface.IsHitTestVisible = true;
//Display control in modal surface
ModalSurface.Children.Add(host);
//Block until ModalHost is done
while (ModalSurface.IsHitTestVisible)
{
DoEvents();
}
}
private void DoEvents()
{
var frame = new DispatcherFrame();
Dispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
private object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
public void CloseModal()
{
//Remove any controls from the modal surface and make UI available again
ModalSurface.Children.Clear();
ModalSurface.IsHitTestVisible = false;
WindowSurface.Effect = null;
}
私のModalHostは、アニメーションやその他のサポートを備えた別の要素をホストするように設計されたユーザーコントロールです。