Second pass at modal
This commit is contained in:
@ -28,7 +28,9 @@ namespace Aurora.Design.Views.Main
|
||||
/// <param name="media"></param>
|
||||
public delegate Task SetPlayerDelegate(BaseMedia media, PlayAction action);
|
||||
public delegate bool GetIsPlayingDelegate();
|
||||
public delegate Task<object> ShowModalDelegate<T>(Type view, Type viewModel);
|
||||
public delegate void ShowModalDelegate(Type view, BaseDialogViewModel viewModel);
|
||||
|
||||
public delegate void HideModalDelegate();
|
||||
public delegate void FinishDialogDelegate();
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
@ -175,7 +177,8 @@ namespace Aurora.Design.Views.Main
|
||||
{
|
||||
return _playerService.PlaybackState == PlaybackState.Playing;
|
||||
};
|
||||
vm.ShowModal = this.ShowModal<object>;
|
||||
vm.ShowModal = this.ShowModal;
|
||||
vm.HideModal = this.HideModal;
|
||||
|
||||
}
|
||||
|
||||
@ -234,40 +237,29 @@ namespace Aurora.Design.Views.Main
|
||||
|
||||
}
|
||||
|
||||
private Task<object> ShowModal<T>(Type view, Type viewModel)
|
||||
private void ShowModal(Type view, BaseDialogViewModel viewModel)
|
||||
{
|
||||
return Task<object>.Run(() =>
|
||||
{
|
||||
object returnObj = null;
|
||||
ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent");
|
||||
var vw = (View)Activator.CreateInstance(view);
|
||||
|
||||
ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent");
|
||||
var vw = (View)Activator.CreateInstance(view);
|
||||
BaseDialogViewModel vm = (BaseDialogViewModel)Activator.CreateInstance(viewModel);
|
||||
vw.BindingContext = viewModel;
|
||||
|
||||
vw.BindingContext = vm;
|
||||
//Set modal container content
|
||||
modalContainer.Content = vw;
|
||||
|
||||
//Set modal container content
|
||||
modalContainer.Content = vw;
|
||||
//Set visibility
|
||||
ChangeModalVisiblity(true);
|
||||
}
|
||||
|
||||
//Set visibility
|
||||
ChangeModalVisiblity(true);
|
||||
|
||||
AutoResetEvent autoResetEvent = new AutoResetEvent(false);
|
||||
//Finish is executed by modal
|
||||
vm.Finish = () =>
|
||||
{
|
||||
ChangeModalVisiblity(false);
|
||||
returnObj = vm.ReturnObject;
|
||||
autoResetEvent.Set();
|
||||
};
|
||||
autoResetEvent.WaitOne();
|
||||
return returnObj;
|
||||
});
|
||||
private void HideModal()
|
||||
{
|
||||
ChangeModalVisiblity(false);
|
||||
}
|
||||
|
||||
private void ChangeModalVisiblity(bool isVisible)
|
||||
{
|
||||
Modal.IsVisible = isVisible;
|
||||
Content.IsVisible = !isVisible;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user