-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
524d05f
commit 9bdfdea
Showing
16 changed files
with
982 additions
and
0 deletions.
There are no files selected for viewing
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
Binary file not shown.
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,24 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.ReactiveUI; | ||
|
||
namespace VirtualPanelDemo.NetCore | ||
{ | ||
class Program | ||
{ | ||
// Initialization code. Don't use any Avalonia, third-party APIs or any | ||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized | ||
// yet and stuff might break. | ||
[STAThread] | ||
public static void Main(string[] args) => BuildAvaloniaApp() | ||
.StartWithClassicDesktopLifetime(args); | ||
|
||
// Avalonia configuration, don't remove; also used by visual designer. | ||
public static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure<App>() | ||
.UsePlatformDetect() | ||
.LogToTrace() | ||
.UseReactiveUI(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
samples/VirtualPanelDemo.NetCore/VirtualPanelDemo.NetCore.csproj
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,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' Or '$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' Or '$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<OutputType>WinExe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<IsPackable>False</IsPackable> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release</Configurations> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AvaloniaResource Include="Assets\**" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\build\Base.props" /> | ||
<Import Project="..\..\build\ReferenceAssemblies.props" /> | ||
<Import Project="..\..\build\Avalonia.props" /> | ||
<Import Project="..\..\build\Avalonia.Desktop.props" /> | ||
<Import Project="..\..\build\Avalonia.Diagnostics.props" /> | ||
<Import Project="..\..\build\Avalonia.ReactiveUI.props" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\DataVirtualization\DataVirtualization.csproj" /> | ||
<ProjectReference Include="..\..\src\VirtualPanel\VirtualPanel.csproj" /> | ||
<ProjectReference Include="..\VirtualPanelDemo\VirtualPanelDemo.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<UpToDateCheckInput Remove="Views\MainWindow.axaml" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,7 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="VirtualPanelDemo.App"> | ||
<Application.Styles> | ||
<FluentTheme /> | ||
</Application.Styles> | ||
</Application> |
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,27 @@ | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace VirtualPanelDemo; | ||
|
||
public class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
desktop.MainWindow = new MainWindow(); | ||
} | ||
else if (ApplicationLifetime is ISingleViewApplicationLifetime single) | ||
{ | ||
single.MainView = new MainView(); | ||
} | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} |
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,63 @@ | ||
<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:dv="clr-namespace:DataVirtualization;assembly=DataVirtualization" | ||
xmlns:sys="clr-namespace:System;assembly=System.Runtime" | ||
xmlns:vm="clr-namespace:VirtualPanelDemo.ViewModels" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="VirtualPanelDemo.MainView" | ||
x:DataType="vm:MainWindowViewModel" x:CompileBindings="True"> | ||
|
||
<DockPanel> | ||
|
||
<DockPanel DockPanel.Dock="Top" HorizontalAlignment="Center" Background="Gray" x:CompileBindings="False" | ||
IsVisible="False"> | ||
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Extent, StringFormat={}Extent: {0}}" DockPanel.Dock="Top" /> | ||
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Viewport, StringFormat={}Viewport: {0}}" DockPanel.Dock="Top" /> | ||
<TextBlock Margin="6,0,6,0" Text="{Binding #ScrollViewer.Offset, StringFormat={}Offset: {0}}" DockPanel.Dock="Top" /> | ||
<TextBlock Margin="6,0,6,0" Text="{Binding Count, StringFormat={}Count: {0}}" DockPanel.Dock="Top" /> | ||
<TextBlock Margin="6,0,6,0" Text="{Binding ItemHeight, StringFormat={}ItemHeight: {0}}" DockPanel.Dock="Top" /> | ||
</DockPanel> | ||
|
||
<ScrollViewer Name="ScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> | ||
|
||
<ScrollViewer.Styles> | ||
<!--<Style Selector="VirtualPanel > ContentControl"> | ||
<Setter Property="Background" Value="Transparent"/> | ||
</Style> | ||
<Style Selector="VirtualPanel > ContentControl:nth-child(2n)"> | ||
<Setter Property="Background" Value="#fff8f8f8"/> | ||
</Style>--> | ||
<Style Selector="VirtualPanel > ContentControl:pointerover"> | ||
<Setter Property="Background" Value="#ffe4e4e4"/> | ||
</Style> | ||
</ScrollViewer.Styles> | ||
|
||
<VirtualPanel ItemsSource="{Binding Items}" | ||
ItemHeight="{Binding ItemHeight}" | ||
ItemWidth="{Binding ItemWidth}" | ||
ScrollMode="Smooth" | ||
Layout="Wrap" | ||
VerticalAlignment="Top" | ||
Name="VirtualPanel"> | ||
<VirtualPanel.ItemTemplate> | ||
<DataTemplate> | ||
<DataTemplate.DataType> | ||
<x:Type TypeName="dv:DataWrapper" x:TypeArguments="sys:String" /> | ||
</DataTemplate.DataType> | ||
<Panel Background="#fff8f8f8" | ||
Margin="2" > | ||
<TextBlock Text="{Binding Data}" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" /> | ||
</Panel> | ||
</DataTemplate> | ||
</VirtualPanel.ItemTemplate> | ||
</VirtualPanel> | ||
|
||
</ScrollViewer> | ||
|
||
</DockPanel> | ||
|
||
</UserControl> |
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,32 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using VirtualPanelDemo.ViewModels; | ||
|
||
namespace VirtualPanelDemo; | ||
|
||
public partial class MainView : UserControl | ||
{ | ||
public MainView() | ||
{ | ||
InitializeComponent(); | ||
|
||
var vm = new MainWindowViewModel(2_000_000_000, 100, 100, 100); | ||
|
||
DataContext = vm; | ||
|
||
var vp = this.FindControl<VirtualPanel.VirtualPanel>("VirtualPanel"); | ||
|
||
if (vm.Items is { }) | ||
{ | ||
vm.Items.CollectionChanged += (_, _) => | ||
{ | ||
vp.InvalidateMeasure(); | ||
}; | ||
} | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
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,13 @@ | ||
<Window 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:VirtualPanelDemo" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="635" | ||
WindowState="Normal" WindowStartupLocation="CenterScreen" | ||
Width="800" Height="635" | ||
UseLayoutRounding="True" | ||
x:Class="VirtualPanelDemo.MainWindow" | ||
Title="VirtualPanel Demo"> | ||
<local:MainView/> | ||
</Window> |
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,25 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Rendering; | ||
using VirtualPanelDemo.ViewModels; | ||
|
||
namespace VirtualPanelDemo; | ||
|
||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
//RendererDiagnostics.DebugOverlays = RendererDebugOverlays.Fps | RendererDebugOverlays.LayoutTimeGraph | RendererDebugOverlays.RenderTimeGraph; | ||
RendererDiagnostics.DebugOverlays = RendererDebugOverlays.Fps; | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
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,36 @@ | ||
using System.Collections.Generic; | ||
using DataVirtualization; | ||
|
||
namespace VirtualPanelDemo.ViewModels | ||
{ | ||
public class ItemProvider : IItemsProvider<string> | ||
{ | ||
private readonly int _count; | ||
|
||
public ItemProvider(int count) | ||
{ | ||
_count = count; | ||
} | ||
|
||
public int FetchCount() | ||
{ | ||
return _count; | ||
} | ||
|
||
public IList<string> FetchRange(int startIndex, int pageCount, out int overallCount) | ||
{ | ||
var result = new List<string>(); | ||
var endIndex = startIndex + pageCount; | ||
|
||
overallCount = _count; | ||
|
||
for (var i = startIndex; i < endIndex; i++) | ||
{ | ||
//result.Add($"Item {i}"); | ||
result.Add($"{i}"); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
samples/VirtualPanelDemo/ViewModels/MainWindowViewModel.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,44 @@ | ||
using DataVirtualization; | ||
using ReactiveUI; | ||
|
||
namespace VirtualPanelDemo.ViewModels; | ||
|
||
public class MainWindowViewModel : ReactiveObject | ||
{ | ||
private AsyncVirtualizingCollection<string>? _items; | ||
private double _itemHeight; | ||
private double _itemWidth; | ||
|
||
public AsyncVirtualizingCollection<string>? Items | ||
{ | ||
get => _items; | ||
set => this.RaiseAndSetIfChanged(ref _items, value); | ||
} | ||
|
||
public double ItemHeight | ||
{ | ||
get => _itemHeight; | ||
set => this.RaiseAndSetIfChanged(ref _itemHeight, value); | ||
} | ||
|
||
public double ItemWidth | ||
{ | ||
get => _itemWidth; | ||
set => this.RaiseAndSetIfChanged(ref _itemWidth, value); | ||
} | ||
|
||
public int Count { get; } | ||
|
||
public void RaiseCountChanged() | ||
{ | ||
this.RaisePropertyChanged(nameof(Count)); | ||
} | ||
|
||
public MainWindowViewModel(int count, int pageSize, int itemHeight, int itemWidth) | ||
{ | ||
Items = new AsyncVirtualizingCollection<string>(new ItemProvider(count), pageSize, 5000); | ||
ItemHeight = itemHeight; | ||
ItemWidth = itemWidth; | ||
Count = count; | ||
} | ||
} |
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<IsPackable>False</IsPackable> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AvaloniaResource Include="Assets\**" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\build\Base.props" /> | ||
<Import Project="..\..\build\ReferenceAssemblies.props" /> | ||
<Import Project="..\..\build\Avalonia.props" /> | ||
<Import Project="..\..\build\Avalonia.Themes.Fluent.props" /> | ||
<Import Project="..\..\build\Avalonia.Diagnostics.props" /> | ||
<Import Project="..\..\build\Avalonia.ReactiveUI.props" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\DataVirtualization\DataVirtualization.csproj" /> | ||
<ProjectReference Include="..\..\src\VirtualPanel\VirtualPanel.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,3 @@ | ||
using Avalonia.Metadata; | ||
|
||
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "VirtualPanel")] |
Oops, something went wrong.