WPF custom title bar #4468
Answered
by
MichelMichels
MichelMichels
asked this question in
Q&A
-
Does anyone have a working custom title bar in WPF? I tried putting one in my Main window, but it gets removed on startup. |
Beta Was this translation helpful? Give feedback.
Answered by
MichelMichels
Sep 6, 2022
Replies: 1 comment
-
I managed to write it myself with a custom MvxWpfViewPresenter. public class CustomTitleBarWpfViewPresenter : MvxWpfViewPresenter
{
public CustomTitleBarWpfViewPresenter(ContentControl root) : base(root)
{
}
protected override Task<bool> ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request)
{
var contentControl = FrameworkElementsDictionary.Keys.FirstOrDefault(w => (w as MvxWindow)?.Identifier == attribute.WindowIdentifier) ?? FrameworkElementsDictionary.Keys.Last();
if (!attribute.StackNavigation && FrameworkElementsDictionary[contentControl].Any())
FrameworkElementsDictionary[contentControl].Pop(); // Close previous view
FrameworkElementsDictionary[contentControl].Push(element);
if (contentControl.Content is Panel panel)
{
var mvxContent = panel.Children.OfType<ContentControl>().SingleOrDefault(x => x.Name == "MvxContent");
if(mvxContent != null)
{
mvxContent.Content = element;
}
}
else
{
contentControl.Content = element;
}
return Task.FromResult(true);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MichelMichels
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I managed to write it myself with a custom MvxWpfViewPresenter.
This code expects a panel directly inside MainWindow and child ContentControl with x:Name="MvxContent".