This commit is contained in:
TheXamlGuy
2024-02-15 20:59:36 +00:00
parent 6f5f6f8cfe
commit 41b9d5e0fc
5 changed files with 39 additions and 20 deletions
+12 -8
View File
@@ -3,27 +3,31 @@ using System.Reflection;
namespace Hyperbar.UI.Windows;
public class ViewModelContentBinder(NavigationTargetCollection contents) :
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)
if (!contents.ContainsKey(attribute.Name))
{
contents.Add(attribute.Name, content);
void HandleUnloaded(object sender, RoutedEventArgs args)
if (view.FindName(attribute.Name) is FrameworkElement content)
{
view.Unloaded -= HandleUnloaded;
contents.Remove(attribute.Name);
}
contents.Add(attribute.Name, content);
void HandleUnloaded(object sender, RoutedEventArgs args)
{
view.Unloaded -= HandleUnloaded;
contents.Remove(attribute.Name);
}
view.Unloaded += HandleUnloaded;
view.Unloaded += HandleUnloaded;
}
}
}
}
@@ -9,14 +9,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.Triggers" Version="8.0.240109" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240205001-preview1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-preview.1.24080.9" />
<PackageReference Include="CustomExtensions.WinUI" Version="0.1.10-beta" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Controls.Windows\Hyperbar.Controls.Windows.csproj" />
@@ -5,7 +5,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers">
xmlns:triggers="using:CommunityToolkit.WinUI">
<UserControl.Resources>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
+24 -7
View File
@@ -6,11 +6,28 @@
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<NavigationView
x:Name="Settings"
IsBackButtonVisible="Collapsed"
IsPaneToggleButtonVisible="False"
IsSettingsVisible="False"
MenuItemTemplateSelector="{Binding ViewModelTemplateSelector}"
MenuItemsSource="{x:Bind ViewModel, Mode=OneWay}" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="43" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock
Margin="15,0,0,0"
VerticalAlignment="Center"
Text="Settings" />
</Border>
<NavigationView
Grid.Row="1"
IsBackButtonVisible="Collapsed"
IsPaneToggleButtonVisible="False"
IsSettingsVisible="False"
MenuItemTemplateSelector="{Binding ViewModelTemplateSelector}"
MenuItemsSource="{x:Bind ViewModel, Mode=OneWay}">
<ContentControl
x:Name="Settings"
Margin="12"
HorizontalContentAlignment="Stretch" />
</NavigationView>
</Grid>
</Window>
+1
View File
@@ -1,5 +1,6 @@
using Hyperbar.UI.Windows;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
namespace Hyperbar.Windows;