Last active
December 20, 2015 01:59
-
-
Save cureos/6053471 to your computer and use it in GitHub Desktop.
WPF specific view presenter class supporting closing an MVVMCross based application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvxCloseableWpfViewPresenter : MvxWpfViewPresenter | |
{ | |
#region FIELDS | |
private readonly Window _window; | |
#endregion | |
#region CONSTRUCTORS | |
public MvxCloseableWpfViewPresenter(Window window) | |
{ | |
if (window == null) throw new ArgumentNullException("window"); | |
_window = window; | |
} | |
#endregion | |
#region METHODS | |
public override void Present(FrameworkElement frameworkElement) | |
{ | |
_window.Content = frameworkElement; | |
} | |
public override void ChangePresentation(MvxPresentationHint hint) | |
{ | |
IMvxWpfView view; | |
var closeHint = hint as MvxClosePresentationHint; | |
if (closeHint != null && (view = _window.Content as IMvxWpfView) != null && | |
ReferenceEquals(closeHint.ViewModelToClose, view.ViewModel)) | |
_window.Close(); | |
base.ChangePresentation(hint); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Sir.
I used your code. Now I can show sub window and close it.But there is a little different in ChangePresentation method.Maybe it's not good.I hope can get your guide.
Thanks.
public class MvxWindowViewPresenter : MvxWpfViewPresenter
{
private readonly ContentControl _contentControl;