initial commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="QuickStartExample.App">
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
|
||||
<StyleInclude Source="avares://Avalonia.PropertyGrid/Controls/PropertyGrid.axaml" />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -0,0 +1,23 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace QuickStartExample;
|
||||
|
||||
public class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:pg="using:Avalonia.PropertyGrid.Controls"
|
||||
xmlns:models="using:QuickStartExample.Models"
|
||||
x:Class="QuickStartExample.MainWindow"
|
||||
x:DataType="models:Vehicle"
|
||||
Title="QuickStart - PropertyGrid Example"
|
||||
Width="900"
|
||||
Height="650">
|
||||
|
||||
<Grid RowDefinitions="Auto,*,Auto" Margin="15">
|
||||
|
||||
<!-- Header Section -->
|
||||
<Border Grid.Row="0"
|
||||
Padding="15"
|
||||
Background="#0078D4"
|
||||
CornerRadius="6"
|
||||
Margin="0,0,0,15">
|
||||
<StackPanel>
|
||||
<TextBlock Text="PropertyGrid Quick Start Example"
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
Foreground="White" />
|
||||
<TextBlock Text="Edit vehicle properties using the PropertyGrid"
|
||||
FontSize="13"
|
||||
Foreground="White"
|
||||
Opacity="0.9"
|
||||
Margin="0,5,0,0" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- PropertyGrid Section -->
|
||||
<Border Grid.Row="1"
|
||||
BorderBrush="#E0E0E0"
|
||||
BorderThickness="1"
|
||||
CornerRadius="6">
|
||||
<pg:PropertyGrid SelectedObject="{Binding}"
|
||||
ShowCategories="True"
|
||||
ShowDescriptions="True" />
|
||||
</Border>
|
||||
|
||||
<!-- Footer Section -->
|
||||
<Border Grid.Row="2"
|
||||
Padding="10"
|
||||
Background="#F5F5F5"
|
||||
CornerRadius="6"
|
||||
Margin="0,15,0,0">
|
||||
<TextBlock Text="Features: Categories, Multiple types, Descriptions, Read-only, Search"
|
||||
FontSize="12" />
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
|
||||
</Window>
|
||||
@@ -0,0 +1,52 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.LogicalTree;
|
||||
using QuickStartExample.Models;
|
||||
|
||||
namespace QuickStartExample;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
var vehicle = new Vehicle();
|
||||
DataContext = vehicle;
|
||||
|
||||
// Find the PropertyGrid and set its SelectedObject directly
|
||||
this.Opened += (s, e) =>
|
||||
{
|
||||
var propertyGrid = this.FindDescendantOfType<Avalonia.PropertyGrid.Controls.PropertyGrid>();
|
||||
if (propertyGrid != null)
|
||||
{
|
||||
propertyGrid.SelectedObject = vehicle;
|
||||
System.Diagnostics.Debug.WriteLine("PropertyGrid found and SelectedObject set directly");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("PropertyGrid NOT found!");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class ControlExtensions
|
||||
{
|
||||
public static T? FindDescendantOfType<T>(this Control control) where T : class
|
||||
{
|
||||
if (control is T result)
|
||||
return result;
|
||||
|
||||
foreach (var child in control.GetLogicalChildren())
|
||||
{
|
||||
if (child is Control childControl)
|
||||
{
|
||||
var found = FindDescendantOfType<T>(childControl);
|
||||
if (found != null)
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace QuickStartExample.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Simple example class demonstrating PropertyGrid usage
|
||||
/// </summary>
|
||||
public class Vehicle
|
||||
{
|
||||
[Display(Name = "Make", Description = "Vehicle manufacturer", Order = 1)]
|
||||
[Category("Basic Info")]
|
||||
public string Make { get; set; } = "Tesla";
|
||||
|
||||
[Display(Name = "Model", Description = "Vehicle model", Order = 2)]
|
||||
[Category("Basic Info")]
|
||||
public string Model { get; set; } = "Model 3";
|
||||
|
||||
[Display(Name = "Year", Description = "Manufacturing year", Order = 3)]
|
||||
[Category("Basic Info")]
|
||||
public int Year { get; set; } = 2024;
|
||||
|
||||
[Display(Name = "Color", Description = "Vehicle color", Order = 4)]
|
||||
[Category("Appearance")]
|
||||
public string Color { get; set; } = "Red";
|
||||
|
||||
[Display(Name = "Mileage", Description = "Current mileage in miles", Order = 5)]
|
||||
[Category("Status")]
|
||||
public double Mileage { get; set; } = 5000.0;
|
||||
|
||||
[Display(Name = "Is Electric", Description = "Electric vehicle", Order = 6)]
|
||||
[Category("Technical")]
|
||||
public bool IsElectric { get; set; } = true;
|
||||
|
||||
[Display(Name = "Fuel Type", Description = "Type of fuel", Order = 7)]
|
||||
[Category("Technical")]
|
||||
public FuelType FuelType { get; set; } = FuelType.Electric;
|
||||
|
||||
[Display(Name = "Price", Description = "Purchase price", Order = 8)]
|
||||
[Category("Financial")]
|
||||
public decimal Price { get; set; } = 45000.00m;
|
||||
|
||||
[Display(Name = "Purchase Date", Description = "Date of purchase", Order = 9)]
|
||||
[Category("Financial")]
|
||||
public DateTime PurchaseDate { get; set; } = DateTime.Now;
|
||||
|
||||
[Display(Name = "VIN", Description = "Vehicle Identification Number", Order = 10)]
|
||||
[Category("Registration")]
|
||||
[ReadOnly(true)]
|
||||
public string VIN { get; set; } = "1HGBH41JXMN109186";
|
||||
}
|
||||
|
||||
public enum FuelType
|
||||
{
|
||||
Gasoline,
|
||||
Diesel,
|
||||
Electric,
|
||||
Hybrid,
|
||||
Hydrogen
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
|
||||
namespace QuickStartExample;
|
||||
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="12.1.0" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="12.1.0" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.1.0" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Avalonia.PropertyGrid\Avalonia.PropertyGrid.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="QuickStartExample.Desktop"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 / 11 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user