-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added waiting block feature in Avalonia 11 C# sample.
Showing
6 changed files
with
190 additions
and
32 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
playground/EpoxyHello.Avalonia11/Controls/WaitingBlock.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Epoxy - An independent flexible XAML MVVM library for .NET | ||
// Copyright (c) Kouji Matsui (@kozy_kekyo, @[email protected]) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
--> | ||
<UserControl | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:EpoxyHello.Avalonia11.Controls" | ||
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" | ||
x:Class="EpoxyHello.Avalonia11.Controls.WaitingBlock"> | ||
|
||
<UniformGrid Rows="3" Columns="3"> | ||
<Rectangle Fill="{Binding CellBrushes[0]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[1]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[2]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[7]}" /> | ||
<Rectangle Fill="{x:Static Brushes.Transparent}" /> | ||
<Rectangle Fill="{Binding CellBrushes[3]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[6]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[5]}" /> | ||
<Rectangle Fill="{Binding CellBrushes[4]}" /> | ||
</UniformGrid> | ||
</UserControl> |
91 changes: 91 additions & 0 deletions
91
playground/EpoxyHello.Avalonia11/Controls/WaitingBlock.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Epoxy - An independent flexible XAML MVVM library for .NET | ||
// Copyright (c) Kouji Matsui (@kozy_kekyo, @[email protected]) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media; | ||
using Epoxy; | ||
using Epoxy.Supplemental; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading; | ||
|
||
namespace EpoxyHello.Avalonia11.Controls; | ||
|
||
/// <summary> | ||
/// Interaction logic for WaitingBlock.xaml | ||
/// </summary> | ||
public sealed partial class WaitingBlock : UserControl | ||
{ | ||
public static readonly AvaloniaProperty CellBrushesProperty = | ||
AvaloniaProperty.Register<WaitingBlock, ObservableCollection<IImmutableSolidColorBrush>?>( | ||
"CellBrushes"); | ||
|
||
private int currentPosition; | ||
private Timer timer; | ||
|
||
public WaitingBlock() | ||
{ | ||
InitializeComponent(); | ||
this.DataContext = this; | ||
|
||
this.CellBrushes = Enumerable.Range(0, 8). | ||
Select(_ => Brushes.Gray). | ||
ToObservableCollection(); | ||
|
||
this.timer = new Timer(async _ => | ||
{ | ||
if (await UIThread.TryBind()) | ||
{ | ||
this.CellBrushes[this.currentPosition] = Brushes.Gray; | ||
if (++this.currentPosition >= this.CellBrushes.Count) | ||
{ | ||
this.currentPosition = 0; | ||
} | ||
this.CellBrushes[this.currentPosition] = Brushes.Red; | ||
} | ||
}, | ||
null, | ||
TimeSpan.Zero, | ||
TimeSpan.Zero); | ||
} | ||
|
||
private void InitializeComponent() => | ||
AvaloniaXamlLoader.Load(this); | ||
|
||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) | ||
{ | ||
base.OnAttachedToVisualTree(e); | ||
this.timer.Change(TimeSpan.Zero, TimeSpan.FromMilliseconds(300)); | ||
} | ||
|
||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) | ||
{ | ||
this.timer.Change(TimeSpan.Zero, TimeSpan.Zero); | ||
base.OnDetachedFromVisualTree(e); | ||
} | ||
|
||
public ObservableCollection<IImmutableSolidColorBrush>? CellBrushes | ||
{ | ||
get => (ObservableCollection<IImmutableSolidColorBrush>?)GetValue(CellBrushesProperty); | ||
set => SetValue(CellBrushesProperty, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters