Skip to content

Commit

Permalink
fix qr code sample commands
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss committed Jun 7, 2023
1 parent 5503dc6 commit 4b30a9d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion samples/Avalonia.Labs.Catalog/ViewModels/QrViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Avalonia.Media;
using Avalonia.Labs.Qr;
using ReactiveUI;
using System.Collections.ObjectModel;
using static Avalonia.Labs.Qr.QrCode;

namespace Avalonia.Labs.Catalog.ViewModels
{
Expand Down Expand Up @@ -80,6 +82,8 @@ public Color QrCodeBackgroundColor2
set => this.RaiseAndSetIfChanged(ref _qrCodeBackgroundColor2, value);
}

public ObservableCollection<EccLevel> Levels { get; }

static QrViewModel()
{
ViewLocator.Register(typeof(QrViewModel), () => new QrView());
Expand All @@ -89,6 +93,8 @@ public QrViewModel()
{
ResetQrCode();
Title = "Qr Generator";

Levels = new ObservableCollection<EccLevel>(Enum.GetValues<EccLevel>());
}

public void UpdateQrCode(string text)
Expand All @@ -113,9 +119,14 @@ public void RandomizeColors()

QrCodeBackgroundColor1 = Color.FromRgb(newColors[6], newColors[7], newColors[8]);
QrCodeBackgroundColor2 = Color.FromRgb(newColors[9], newColors[10], newColors[11]);

var cuurentCode = QrCodeString;
QrCodeString = string.Empty;

UpdateQrCode(cuurentCode);
}

private void ResetQrCode()
public void ResetQrCode()
{
QrCodeEccLevel = QrCode.EccLevel.Medium;

Expand Down
7 changes: 4 additions & 3 deletions samples/Avalonia.Labs.Catalog/Views/QrView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@
VerticalAlignment="Center"/>
<ComboBox Name="EccLevelComboBox"
Width="{Binding QrCodeSize}"
ItemsSource="{Binding Levels}"
SelectedItem="{Binding QrCodeEccLevel, Mode=TwoWay}" />
</StackPanel>

<StackPanel HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="10">
<Button Content="Randomize Data"
Command="{Binding RandomizeDataCommand}" />
Command="{Binding RandomizeData}" />
<Button Content="Randomize Colors"
Command="{Binding RandomizeColorsCommand}" />
Command="{Binding RandomizeColors}" />
</StackPanel>

<Button Content="Reset QRCode"
HorizontalAlignment="Center"
Command="{Binding ResetQrCodeCommand}" />
Command="{Binding ResetQrCode}" />
</StackPanel>
</Panel>
</UserControl>

0 comments on commit 4b30a9d

Please sign in to comment.