Skip to content

Commit 3465e69

Browse files
committed
Added InfoBarArea to WinUI
1 parent c3c012f commit 3465e69

5 files changed

Lines changed: 67 additions & 7 deletions

File tree

src/Codebreaker.WinUI/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public partial class App : Application
5353
.Configure<ShellPage>("ShellPage"));
5454
services.AddSingleton<IWinUINavigationService, WinUINavigationService>();
5555
services.AddSingleton<INavigationService>(x => x.GetRequiredService<IWinUINavigationService>());
56+
services.AddScoped<IInfoBarService, InfoBarService>();
5657
services.AddScoped<IDialogService, WinUIDialogService>();
5758
services.AddSingleton<ISettingsService, SettingsService>();
5859

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
using Codebreaker.ViewModels;
1+
using Codebreaker.ViewModels.Components;
22
using Microsoft.UI.Xaml.Data;
33

44
namespace CodeBreaker.WinUI.Converters;
55

66
public class InfoBarSeverityConverter : IValueConverter
77
{
8-
public object Convert(object value, Type targetType, object parameter, string language) =>
8+
public object? Convert(object value, Type targetType, object parameter, string language) =>
99
value switch
1010
{
1111
InfoMessageSeverity.Warning => InfoBarSeverity.Warning,
1212
InfoMessageSeverity.Error => InfoBarSeverity.Error,
1313
InfoMessageSeverity.Success => InfoBarSeverity.Success,
14-
_ => InfoBarSeverity.Informational
14+
_ => InfoBarSeverity.Informational,
1515
};
1616

17-
public object ConvertBack(object value, Type targetType, object parameter, string language) =>
17+
public object? ConvertBack(object value, Type targetType, object parameter, string language) =>
1818
value switch
1919
{
2020
InfoBarSeverity.Warning => InfoMessageSeverity.Warning,
2121
InfoBarSeverity.Error => InfoMessageSeverity.Error,
2222
InfoBarSeverity.Success => InfoMessageSeverity.Success,
23-
_ => InfoMessageSeverity.Info
23+
_ => InfoMessageSeverity.Info,
2424
};
2525
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<UserControl
3+
x:Class="CodeBreaker.WinUI.Views.Components.InfoBarArea"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:CodeBreaker.WinUI.Views.Components"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:vmComponents="using:Codebreaker.ViewModels.Components"
10+
xmlns:converters="using:CodeBreaker.WinUI.Converters"
11+
xmlns:toolkitConverters="using:CommunityToolkit.WinUI.UI.Converters"
12+
mc:Ignorable="d">
13+
<UserControl.Resources>
14+
<converters:InfoBarSeverityConverter x:Key="InfoBarSeverityConverter" />
15+
<toolkitConverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
16+
</UserControl.Resources>
17+
<ListView ItemsSource="{x:Bind ViewModel.Messages, Mode=OneWay}" MaxHeight="200" IsItemClickEnabled="False" SelectionMode="None">
18+
<ItemsControl.ItemTemplate>
19+
<DataTemplate x:DataType="vmComponents:InfoMessageViewModel">
20+
<InfoBar
21+
Severity="{x:Bind Severity, Mode=OneTime, Converter={StaticResource InfoBarSeverityConverter}}"
22+
Title="{x:Bind Title, Mode=OneTime}"
23+
Message="{x:Bind Message, Mode=OneTime}"
24+
IsIconVisible="True"
25+
IsClosable="{x:Bind IsClosable, Mode=OneTime}"
26+
CloseButtonCommand="{x:Bind CloseCommand, Mode=OneTime}"
27+
IsOpen="True">
28+
<InfoBar.ActionButton>
29+
<Button
30+
HorizontalAlignment="Right"
31+
Visibility="{x:Bind HasAction, Mode=OneTime, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=False}"
32+
Command="{x:Bind ExecuteActionCommand, Mode=OneTime}"
33+
Content="{x:Bind ActionText, Mode=OneTime}" />
34+
</InfoBar.ActionButton>
35+
</InfoBar>
36+
</DataTemplate>
37+
</ItemsControl.ItemTemplate>
38+
</ListView>
39+
</UserControl>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Codebreaker.ViewModels.Contracts.Services;
2+
3+
namespace CodeBreaker.WinUI.Views.Components;
4+
5+
internal sealed partial class InfoBarArea : UserControl
6+
{
7+
public InfoBarArea()
8+
{
9+
ViewModel = App.GetService<IInfoBarService>();
10+
InitializeComponent();
11+
}
12+
13+
public IInfoBarService ViewModel { get; }
14+
}

src/Codebreaker.WinUI/Views/Pages/ShellPage.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:helpers="using:CodeBreaker.WinUI.Helpers"
88
xmlns:behaviors="using:CodeBreaker.WinUI.Behaviors"
99
xmlns:i="using:Microsoft.Xaml.Interactivity"
10+
xmlns:components="using:CodeBreaker.WinUI.Views.Components"
1011
xmlns:toolkitConverters="using:CommunityToolkit.WinUI.UI.Converters"
1112
xmlns:cme="using:CodeBreaker.WinUI.CustomMarkupExtensions"
1213
xmlns:ca="using:CodeBreaker.WinUI.CustomAttachedProperties"
@@ -72,8 +73,13 @@
7273
</behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
7374
</behaviors:NavigationViewHeaderBehavior>
7475
</i:Interaction.Behaviors>
75-
<Grid Margin="{StaticResource NavigationViewPageContentMargin}">
76-
<Frame x:Name="NavigationFrame" />
76+
<Grid Margin="{StaticResource NavigationViewPageContentMargin}" RowSpacing="{StaticResource Spacing3}">
77+
<Grid.RowDefinitions>
78+
<RowDefinition Height="Auto" />
79+
<RowDefinition />
80+
</Grid.RowDefinitions>
81+
<components:InfoBarArea />
82+
<Frame Grid.Row="1" x:Name="NavigationFrame" />
7783
</Grid>
7884
<NavigationView.FooterMenuItems>
7985
</NavigationView.FooterMenuItems>

0 commit comments

Comments
 (0)