Second pass at modal

This commit is contained in:
watsonb8 2019-12-18 22:32:08 -05:00
parent 8affc8d2af
commit 1e7e71f29d
3 changed files with 29 additions and 31 deletions

View File

@ -56,7 +56,9 @@ namespace Aurora.Design.Views
/// <value></value>
public GetIsPlayingDelegate IsPlaying { get; set; }
public ShowModalDelegate<object> ShowModal { get; set; }
public ShowModalDelegate ShowModal { get; set; }
public HideModalDelegate HideModal { get; set; }
#endregion Player

View File

@ -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;
}
}
}

View File

@ -127,10 +127,12 @@ namespace Aurora.Design.Views.Party
else
{
//Open host selection modal
var modalResult = await this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), typeof(NewPartyDialogViewModel));
if (modalResult is ConnectionDetails)
NewPartyDialogViewModel vm = new NewPartyDialogViewModel();
ConnectionDetails details = new ConnectionDetails();
vm.Finish = () =>
{
ConnectionDetails details = modalResult as ConnectionDetails;
this.HideModal();
details = vm.ReturnObject as ConnectionDetails;
_hostname = details.HostName;
switch (details.ConnectionType)
{
@ -145,7 +147,9 @@ namespace Aurora.Design.Views.Party
break;
}
}
}
};
this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), vm);
}
}