Skip to content

Commit

Permalink
Make demo use compiled bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Feb 10, 2024
1 parent c47ee6f commit e992249
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 65 deletions.
2 changes: 0 additions & 2 deletions Material.Demo/Material.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<IsPackable>false</IsPackable>

<AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Material.Demo/Pages/ExpandersDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:viewModels="clr-namespace:Material.Demo.ViewModels"
x:Class="Material.Demo.Pages.ExpandersDemo">
x:Class="Material.Demo.Pages.ExpandersDemo"
x:DataType="viewModels:ExpanderDemoViewModel">
<UserControl.DataContext>
<viewModels:ExpanderDemoViewModel/>
</UserControl.DataContext>
Expand Down
4 changes: 3 additions & 1 deletion Material.Demo/Pages/FieldsDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
x:Class="Material.Demo.Pages.FieldsDemo">
xmlns:viewModels="clr-namespace:Material.Demo.ViewModels"
x:Class="Material.Demo.Pages.FieldsDemo"
x:DataType="viewModels:TextFieldsViewModel">
<UserControl.Resources>
<system:String x:Key="TextFieldTip1">Only numerics in this field</system:String>
</UserControl.Resources>
Expand Down
4 changes: 3 additions & 1 deletion Material.Demo/Pages/Home.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Material.Demo.Pages.Home">
xmlns:pages="clr-namespace:Material.Demo.Pages"
x:Class="Material.Demo.Pages.Home"
x:DataType="pages:Home">
<!--UserControl.Resources>
<conv:EnumDescriptionConverter x:Key="GetDescription"/>
</UserControl.Resources-->
Expand Down
3 changes: 2 additions & 1 deletion Material.Demo/Pages/IconsDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
xmlns:assists="clr-namespace:Material.Styles.Assists;assembly=Material.Styles"
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Material.Demo.Pages.IconsDemo">
x:Class="Material.Demo.Pages.IconsDemo"
x:DataType="viewModels:IconsDemoViewModel">
<UserControl.Resources>
<converters:StringJoinConverter x:Key="StringJoinConverter"
Separator="{x:Static system:Environment.NewLine}" />
Expand Down
4 changes: 3 additions & 1 deletion Material.Demo/Pages/ProgressIndicatorDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:showMeTheXaml="clr-namespace:ShowMeTheXaml;assembly=ShowMeTheXaml.Avalonia"
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
x:Class="Material.Demo.Pages.ProgressIndicatorDemo">
xmlns:viewModels="clr-namespace:Material.Demo.ViewModels"
x:Class="Material.Demo.Pages.ProgressIndicatorDemo"
x:DataType="viewModels:ProgressIndicatorDemoViewModel">
<StackPanel Margin="16, 0">
<TextBlock Classes="Headline4 Subheadline" Text="Progress Indicator" />
<WrapPanel>
Expand Down
60 changes: 2 additions & 58 deletions Material.Demo/Pages/ProgressIndicatorDemo.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,14 @@
using System.Timers;
using Avalonia;
using Avalonia.Controls;
using Material.Demo.ViewModels;

namespace Material.Demo.Pages {
public partial class ProgressIndicatorDemo : UserControl {
private readonly Context context;
private readonly Timer timer;
private int caseProgress;

public ProgressIndicatorDemo() {
InitializeComponent();

timer = new Timer(1000);
timer.Elapsed += Timer_Elapsed;

DataContext = context = new Context();

AttachedToVisualTree += ProgressIndicatorDemo_AttachedToVisualTree;
}

private void ProgressIndicatorDemo_AttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) {
timer.Start();
}

private void Timer_Elapsed(object? sender, ElapsedEventArgs e) {
context.Progress = SwitchProgress();
}

private double SwitchProgress() {
switch (caseProgress) {
case 0:
caseProgress++;
return 30;
case 1:
caseProgress++;
return 45;
case 2:
caseProgress++;
return 50;
case 3:
caseProgress++;
return 80;
case 4:
caseProgress++;
return 100;
case 5:
caseProgress = 0;
return 0;
default:
caseProgress = 0;
return 0;
}
}

public class Context : INotifyPropertyChanged {
private double m_Progress;

public double Progress {
get => m_Progress;
set {
m_Progress = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Progress)));
}
}

public event PropertyChangedEventHandler? PropertyChanged;
DataContext = new ProgressIndicatorDemoViewModel();
}
}
}
52 changes: 52 additions & 0 deletions Material.Demo/ViewModels/ProgressIndicatorDemoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Timers;

namespace Material.Demo.ViewModels;

public class ProgressIndicatorDemoViewModel : ViewModelBase {
private readonly Timer _timer;
private double _progress;
private int _progressSate;

public ProgressIndicatorDemoViewModel() {
_timer = new Timer(1000);
_timer.Elapsed += Timer_Elapsed;
}

public double Progress {
get => _progress;
set {
_progress = value;
OnPropertyChanged();
}
}

private void Timer_Elapsed(object? sender, ElapsedEventArgs e) {
Progress = SwitchProgress();
}

private double SwitchProgress() {
switch (_progressSate) {
case 0:
_progressSate++;
return 30;
case 1:
_progressSate++;
return 45;
case 2:
_progressSate++;
return 50;
case 3:
_progressSate++;
return 80;
case 4:
_progressSate++;
return 100;
case 5:
_progressSate = 0;
return 0;
default:
_progressSate = 0;
return 0;
}
}
}

0 comments on commit e992249

Please sign in to comment.