Get ContentControl navigation working

This commit is contained in:
TheXamlGuy
2024-02-11 18:09:22 +00:00
parent 565c6866d8
commit 812556f8b0
133 changed files with 335 additions and 195 deletions
@@ -0,0 +1,31 @@
using Microsoft.UI.Xaml;
using System.Reflection;
namespace Hyperbar.UI.Windows;
public class ViewModelContentBinder(NavigationTargetCollection contents) :
IViewModelContentBinder
{
public void Bind(FrameworkElement view,
object context)
{
if (context.GetType().GetCustomAttributes<NavigationTargetAttribute>()
is IEnumerable<NavigationTargetAttribute> attributes)
{
foreach (NavigationTargetAttribute attribute in attributes)
{
if (view.FindName(attribute.Name) is FrameworkElement content)
{
contents.Add(attribute.Name, content);
void HandleUnloaded(object sender, RoutedEventArgs args)
{
view.Unloaded -= HandleUnloaded;
contents.Remove(attribute.Name);
}
view.Unloaded += HandleUnloaded;
}
}
}
}
}