Skip to content

Commit b1965c2

Browse files
authored
Merge pull request #30 from TheJoeFin/breakout-more-XAML-controls
Breakout more xaml controls
2 parents c4f7f8f + dcd5a63 commit b1965c2

15 files changed

Lines changed: 603 additions & 358 deletions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl
3+
x:Class="Simple_QR_Code_Maker.Controls.HistoryRowItem"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:converters="using:Simple_QR_Code_Maker.Converters"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:local="using:Simple_QR_Code_Maker.Controls"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:models="using:Simple_QR_Code_Maker.Models"
11+
mc:Ignorable="d">
12+
13+
<UserControl.Resources>
14+
<converters:ColorToBrushConverter x:Key="ColorToBrush" />
15+
</UserControl.Resources>
16+
17+
<Grid Margin="2" Padding="0,6">
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="auto" />
20+
<RowDefinition Height="auto" />
21+
<RowDefinition Height="auto" />
22+
</Grid.RowDefinitions>
23+
<TextBlock
24+
Style="{StaticResource BodyTextStyle}"
25+
Text="{x:Bind Data.CodesContent, Mode=OneWay}"
26+
TextTrimming="WordEllipsis" />
27+
<StackPanel
28+
Grid.Row="1"
29+
Orientation="Horizontal"
30+
Spacing="8">
31+
<StackPanel.Resources>
32+
<Style TargetType="Rectangle">
33+
<Setter Property="Width" Value="16" />
34+
<Setter Property="Height" Value="10" />
35+
</Style>
36+
</StackPanel.Resources>
37+
<Rectangle Fill="{x:Bind Data.Foreground, Converter={StaticResource ColorToBrush}, Mode=OneWay}" />
38+
<Rectangle Fill="{x:Bind Data.Background, Converter={StaticResource ColorToBrush}, Mode=OneWay}" />
39+
<TextBlock Text="{x:Bind Data.ErrorCorrectionLevelAsString}" />
40+
</StackPanel>
41+
<TextBlock
42+
Grid.Row="2"
43+
Style="{StaticResource CaptionTextBlockStyle}"
44+
Text="{x:Bind Data.SaveDateAsString, Mode=OneWay}"
45+
TextTrimming="WordEllipsis" />
46+
</Grid>
47+
</UserControl>
48+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Simple_QR_Code_Maker.Models;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public sealed partial class HistoryRowItem : UserControl
8+
{
9+
10+
11+
public HistoryItem Data
12+
{
13+
get { return (HistoryItem)GetValue(DataProperty); }
14+
set { SetValue(DataProperty, value); }
15+
}
16+
17+
public static readonly DependencyProperty DataProperty =
18+
DependencyProperty.Register("Data", typeof(HistoryItem), typeof(HistoryRowItem), new PropertyMetadata(null));
19+
20+
21+
22+
public HistoryRowItem()
23+
{
24+
this.InitializeComponent();
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Button
3+
x:Class="Simple_QR_Code_Maker.Controls.IconAndTextButton"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:Simple_QR_Code_Maker.Controls"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Style="{StaticResource DefaultButtonStyle}"
10+
mc:Ignorable="d">
11+
12+
<StackPanel Orientation="Horizontal" Spacing="10">
13+
<Viewbox Height="16" Child="{x:Bind Icon}" />
14+
<TextBlock Text="{x:Bind Text}" />
15+
</StackPanel>
16+
</Button>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
4+
namespace Simple_QR_Code_Maker.Controls;
5+
6+
public sealed partial class IconAndTextButton : Button
7+
{
8+
public IconAndTextButton()
9+
{
10+
this.InitializeComponent();
11+
}
12+
13+
public string Text
14+
{
15+
get { return (string)GetValue(TextProperty); }
16+
set { SetValue(TextProperty, value); }
17+
}
18+
19+
public static readonly DependencyProperty TextProperty =
20+
DependencyProperty.Register("Text", typeof(string), typeof(IconAndTextButton), new PropertyMetadata(""));
21+
22+
public UIElement Icon
23+
{
24+
get { return (UIElement)GetValue(IconProperty); }
25+
set { SetValue(IconProperty, value); }
26+
}
27+
28+
public static readonly DependencyProperty IconProperty =
29+
DependencyProperty.Register("Icon", typeof(UIElement), typeof(IconAndTextButton), new PropertyMetadata(null));
30+
31+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl
3+
x:Class="Simple_QR_Code_Maker.Controls.QrCodeImageControl"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:Simple_QR_Code_Maker.Controls"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Grid
12+
Margin="4"
13+
HorizontalAlignment="Center"
14+
VerticalAlignment="Center">
15+
<Image
16+
x:Name="QrCodeImage"
17+
Width="285"
18+
Height="285"
19+
CanDrag="True"
20+
DragStarting="QrCodeImage_DragStarting"
21+
Source="{x:Bind Data.CodeAsBitmap,
22+
Mode=OneWay}"
23+
ToolTipService.ToolTip="{x:Bind Data.CodeAsText,
24+
Mode=OneWay}">
25+
<Image.ContextFlyout>
26+
<MenuFlyout>
27+
<MenuFlyoutItem
28+
Command="{x:Bind Data.SaveCodePngContextCommand,
29+
Mode=OneWay}"
30+
Icon="Save"
31+
Text="Save PNG..." />
32+
<MenuFlyoutItem
33+
Command="{x:Bind Data.CopyCodePngContextCommand,
34+
Mode=OneWay}"
35+
Icon="Copy"
36+
Text="Copy PNG" />
37+
<MenuFlyoutSeparator />
38+
<MenuFlyoutItem
39+
Command="{x:Bind Data.SaveCodeSvgContextCommand,
40+
Mode=OneWay}"
41+
Icon="Save"
42+
Text="Save SVG..." />
43+
<MenuFlyoutItem
44+
Command="{x:Bind Data.CopyCodeSvgContextCommand,
45+
Mode=OneWay}"
46+
Icon="Copy"
47+
Text="Copy SVG" />
48+
<MenuFlyoutItem
49+
Command="{x:Bind Data.CopyCodeSvgTextContextCommand,
50+
Mode=OneWay}"
51+
Icon="Copy"
52+
Text="Copy SVG as Text" />
53+
</MenuFlyout>
54+
</Image.ContextFlyout>
55+
</Image>
56+
<InfoBar
57+
IsOpen="{x:Bind Data.UrlWarning,
58+
Mode=OneWay}"
59+
Message="QR Code not a URL"
60+
Severity="Warning"
61+
ToolTipService.ToolTip="This warning can be disabled in settings" />
62+
</Grid>
63+
</UserControl>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.Foundation;
7+
using Windows.Foundation.Collections;
8+
using Microsoft.UI.Xaml;
9+
using Microsoft.UI.Xaml.Controls;
10+
using Microsoft.UI.Xaml.Controls.Primitives;
11+
using Microsoft.UI.Xaml.Data;
12+
using Microsoft.UI.Xaml.Input;
13+
using Microsoft.UI.Xaml.Media;
14+
using Microsoft.UI.Xaml.Navigation;
15+
using Simple_QR_Code_Maker.Models;
16+
using Microsoft.UI.Xaml.Media.Imaging;
17+
using Simple_QR_Code_Maker.Helpers;
18+
using Windows.ApplicationModel.DataTransfer;
19+
using Windows.Storage;
20+
using Simple_QR_Code_Maker.Extensions;
21+
using CommunityToolkit.Mvvm.Messaging;
22+
23+
24+
namespace Simple_QR_Code_Maker.Controls;
25+
26+
public sealed partial class QrCodeImageControl : UserControl
27+
{
28+
public BarcodeImageItem Data
29+
{
30+
get { return (BarcodeImageItem)GetValue(DataProperty); }
31+
set { SetValue(DataProperty, value); }
32+
}
33+
34+
public static readonly DependencyProperty DataProperty =
35+
DependencyProperty.Register("Data", typeof(BarcodeImageItem), typeof(QrCodeImageControl), new PropertyMetadata(null));
36+
37+
38+
public QrCodeImageControl()
39+
{
40+
InitializeComponent();
41+
}
42+
43+
private async void QrCodeImage_DragStarting(UIElement sender, DragStartingEventArgs args)
44+
{
45+
if (sender is not Image image || image.Source is not WriteableBitmap bitmap)
46+
return;
47+
48+
DragOperationDeferral deferral = args.GetDeferral();
49+
StorageFolder folder = ApplicationData.Current.LocalCacheFolder;
50+
string? imageNameFileName = $"{ToolTipService.GetToolTip(image)}" ?? "QR_Code";
51+
// remove characters that are not allowed in file names
52+
imageNameFileName = imageNameFileName.ToSafeFileName();
53+
imageNameFileName += ".png";
54+
StorageFile file = await folder.CreateFileAsync(imageNameFileName, CreationCollisionOption.ReplaceExisting);
55+
bool success = await bitmap.SavePngToStorageFile(file);
56+
57+
if (!success)
58+
{
59+
deferral.Complete();
60+
return;
61+
}
62+
63+
WeakReferenceMessenger.Default.Send(new SaveHistoryMessage());
64+
args.Data.SetStorageItems(new[] { file });
65+
args.Data.RequestedOperation = DataPackageOperation.Copy;
66+
deferral.Complete();
67+
}
68+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public partial class ScanIcon : FontIcon
8+
{
9+
public ScanIcon()
10+
{
11+
this.FontFamily = (FontFamily)Application.Current.Resources["SymbolThemeFontFamily"];
12+
this.Glyph = "\uEE6F";
13+
}
14+
}
15+

0 commit comments

Comments
 (0)