### Install Nuke Global Tool Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Install the Nuke build system globally to manage Avalonia's build process. ```bash dotnet tool install --global Nuke.GlobalTool ``` -------------------------------- ### Install .NET Workloads Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Install the necessary .NET workloads for cross-platform development. This command may require administrator privileges on Unix-based systems. ```bash dotnet workload install android ios tvos maccatalyst wasm-tools ``` -------------------------------- ### Install Avalonia via Package Manager Source: https://github.com/avaloniaui/avalonia/blob/master/readme.md Commands to manually install the core Avalonia and desktop platform packages using the NuGet Package Manager console. ```powershell Install-Package Avalonia Install-Package Avalonia.Desktop ``` -------------------------------- ### Download and Install .NET Core Runtime Source: https://github.com/avaloniaui/avalonia/wiki/Run-an-Avalonia-application-on-Raspberry-Pi Downloads the .NET Core 2.0 runtime tarball for ARM architecture, extracts it to /opt/dotnet, and creates a symbolic link to the binary for global access. ```bash curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet sudo ln -s /opt/dotnet/dotnet /usr/local/bin ``` -------------------------------- ### Install .NET Core Runtime Dependencies on Raspberry Pi Source: https://github.com/avaloniaui/avalonia/wiki/Run-an-Avalonia-application-on-Raspberry-Pi Installs the necessary system packages required to run the .NET Core runtime on a Debian-based Linux distribution like Raspbian. ```bash sudo apt-get install curl libunwind8 gettext apt-transport-https ``` -------------------------------- ### Refactor Platform Options Configuration Source: https://github.com/avaloniaui/avalonia/wiki/Breaking-Changes Demonstrates the migration from manual platform-specific configuration to the fluent 'With' pattern for platform options in Avalonia 0.8. ```csharp // Before (0.7) public static AppBuilder BuildAvaloniaApp() { var builder = AppBuilder.Configure(); if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) builder.UseX11(new X11PlatformOptions() {UseGpu = false}); else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) builder.UseAvaloniaNative(anopts => { anopts.UseGpu = false; anopts.MacOptions.ShowInDock = 0; }); else if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) builder.UseWin32(false, true); return builder; } // After (0.8) public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() .With(new X11PlatformOptions { UseGpu = false }) .With(new AvaloniaNativePlatformOptions { UseGpu = false }) .With(new MacOSPlatformOptions { ShowInDock = false }) .With(new Win32PlatformOptions { UseDeferredRendering = false }); ``` -------------------------------- ### Compile Native Libraries on macOS Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Build and install native libraries required for Avalonia on macOS using the build script. ```bash ./build.sh CompileNative ``` -------------------------------- ### Configure Avalonia Application Entry Point Source: https://github.com/avaloniaui/avalonia/wiki/Breaking-Changes The application entry point now requires a static BuildAvaloniaApp method to support the previewer. This method configures the AppBuilder with platform detection and logging. ```csharp static void Main(string[] args) { BuildAvaloniaApp().Start(); } public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() .LogToDebug(); ``` -------------------------------- ### Enable SSH Root Login on Linux Source: https://github.com/avaloniaui/avalonia/wiki/Remotely-debugging-AvaloniaUI-on-Linux-OSX Commands to install the SSH server and configure root access on Debian/Ubuntu-based systems. This is a prerequisite for remote synchronization and debugging. ```bash sudo apt-get install openssh-server # Edit /etc/ssh/sshd_config and set PermitRootLogin to yes sudo passwd root ``` -------------------------------- ### Configure SimpleTheme in XAML Source: https://github.com/avaloniaui/avalonia/wiki/Breaking-Changes Updates the syntax for including the SimpleTheme in Avalonia 11.0 applications, replacing older StyleInclude approaches. ```xml ``` -------------------------------- ### Configure ItemsControl Virtualization Source: https://github.com/avaloniaui/avalonia/wiki/Breaking-Changes Demonstrates how to toggle virtualization in ItemsControl by defining the ItemsPanel template, replacing the removed VirtualizationMode property. ```xml ``` -------------------------------- ### Access Mouse Device from Visual Root Source: https://github.com/avaloniaui/avalonia/wiki/Breaking-Changes The global MouseDevice context has been removed. Developers must now retrieve the mouse device from the visual root of a control by casting to IInputRoot. ```csharp var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(Point); ``` -------------------------------- ### Enable Avalonia XAML Compiler Debugging (MSBuild) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/debug-xaml-compiler.md Set the `AvaloniaXamlIlDebuggerLaunch` MSBuild property to `true` in your project file to enable debugging of the Avalonia XAML compiler. This will trigger `Debugger.Launch()` when the compiler starts, allowing you to attach a debugger. ```xml true ``` -------------------------------- ### Build and Run ControlCatalog.Desktop Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Navigate to the ControlCatalog.Desktop sample directory, restore dependencies, and run the application. ```bash cd samples\ControlCatalog.Desktop dotnet restore dotnet run ``` -------------------------------- ### Run Build Script on Windows Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Execute the build script on Windows with a Debug configuration. ```bash .\build.ps1 --configuration Debug ``` -------------------------------- ### Setting ComStaticPtr with comnew Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Demonstrates how to assign a new COM object to a ComStaticPtr using the set() method. ```cpp GlDisplay.set(comnew()); ``` -------------------------------- ### Build Avalonia Project with Nuke Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Use Nuke to compile the Avalonia project in Release configuration. ```bash nuke --target Compile --configuration Release ``` -------------------------------- ### Run Build Script on macOS/Linux Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Execute the build script on macOS or Linux with a Debug configuration. ```bash ./build.sh --configuration Debug ``` -------------------------------- ### Using comnew for COM Object Creation Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Shows the convenience of using the comnew factory function to create COM objects and wrap them in a ComPtr, avoiding manual AddRef/Release. ```cpp // Instead of: ComPtr cursor(new Cursor(nsCursor), true); // Write: ComPtr cursor = comnew(nsCursor); ``` -------------------------------- ### Initialize Avalonia UI Controls in C# Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/FieldModifier.txt This C# code snippet demonstrates the InitializeComponent method for a SampleView in Avalonia. It's responsible for loading XAML markup and finding/assigning UI controls such as TextBoxes and Buttons to their corresponding class members. This method is typically auto-generated and should not be manually edited. ```csharp // using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace Sample.App { partial class SampleView { [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] public global::Avalonia.Controls.TextBox FirstNameTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] public global::Avalonia.Controls.TextBox LastNameTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] protected global::Avalonia.Controls.TextBox PasswordTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] private global::Avalonia.Controls.TextBox ConfirmPasswordTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.Button SignUpButton; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.Button RegisterButton; /// /// Wires up the controls and optionally loads XAML markup and attaches dev tools (if Avalonia.Diagnostics package is referenced). /// /// Should the XAML be loaded into the component. [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public void InitializeComponent(bool loadXaml = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } var __thisNameScope__ = this.FindNameScope(); FirstNameTextBox = __thisNameScope__?.Find("FirstNameTextBox"); LastNameTextBox = __thisNameScope__?.Find("LastNameTextBox"); PasswordTextBox = __thisNameScope__?.Find("PasswordTextBox"); ConfirmPasswordTextBox = __thisNameScope__?.Find("ConfirmPasswordTextBox"); SignUpButton = __thisNameScope__?.Find("SignUpButton"); RegisterButton = __thisNameScope__?.Find("RegisterButton"); } } } ``` -------------------------------- ### XAML Markup for Avalonia Control Naming Source: https://github.com/avaloniaui/avalonia/blob/master/src/tools/Avalonia.Generators/README.md Example of an Avalonia XAML file defining a Window with a TextBox named 'UserNameTextBox'. The `x:Class` directive links this XAML to a C# partial class, enabling the source generator to create a typed reference. ```xml ``` -------------------------------- ### ComPtr Usage for Owning COM References Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Demonstrates the correct usage of ComPtr for owning COM references that need to be kept alive, contrasting it with the incorrect use of raw COM pointers in fields. ```cpp ComPtr _window; // correct IAvnWindow* _window; // WRONG — raw COM pointer in a field ``` -------------------------------- ### Import MSBuild Properties for Libraries Source: https://github.com/avaloniaui/avalonia/blob/master/build/readme.md This snippet shows how to import various .props files in an MSBuild project. These files typically define properties and configurations for external libraries such as JetBrains.Annotations, JetBrains.dotMemoryUnit, Magick.NET, SkiaSharp, Splat, and XUnit. ```XML ``` -------------------------------- ### Package Avalonia Project with Nuke Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Build NuGet packages for Avalonia, which also compiles and runs tests, in Release configuration. ```bash nuke --target Package --configuration Release ``` -------------------------------- ### Run Avalonia Tests with Nuke Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Execute tests for the Avalonia project using Nuke in Release configuration. ```bash nuke --target RunTests --configuration Release ``` -------------------------------- ### Import MSBuild Targets for Unit Tests Source: https://github.com/avaloniaui/avalonia/blob/master/build/readme.md This snippet demonstrates importing an MSBuild .targets file. The 'UnitTests.NetCore.targets' file likely contains definitions for tasks and configurations necessary for running unit tests within a .NET Core environment. ```XML ``` -------------------------------- ### COM Return Value Convention Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Illustrates the correct pattern for returning COM interface references using an out-parameter and HRESULT, contrasting it with the error-prone raw pointer return. ```cpp // WRONG — easy to leak or forget Release: IFoo* GetFoo(); // CORRECT — use HRESULT + out-parameter: HRESULT GetFoo(IFoo** ppv); ``` -------------------------------- ### Build Local NuGet Packages (Windows) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds local NuGet packages for AvaloniaUI on Windows using PowerShell. It executes the `CreateNugetPackages` target defined in the build script. ```powershell .\build.ps1 CreateNugetPackages ``` -------------------------------- ### Clone Avalonia Repository Source: https://github.com/avaloniaui/avalonia/blob/master/docs/build.md Use this command to clone the Avalonia repository and its submodules. ```bash git clone --recurse-submodules https://github.com/AvaloniaUI/Avalonia.git ``` -------------------------------- ### Build Local NuGet Packages (Linux/macOS) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds local NuGet packages for AvaloniaUI on Linux or macOS using a shell script. It executes the `CreateNugetPackages` target defined in the build script. ```bash ./build.sh CreateNugetPackages ``` -------------------------------- ### Build NuGet Packages in Release Configuration (Nuke) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds AvaloniaUI NuGet packages in the Release configuration using the Nuke global tool. It specifies the configuration using the `--configuration` parameter. ```bash nuke CreateNugetPackages --configuration Release ``` -------------------------------- ### Build Local NuGet Packages (Nuke Global Tool) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds local NuGet packages for AvaloniaUI using the Nuke global tool, which provides a unified command across all platforms. It executes the `CreateNugetPackages` target. ```bash nuke CreateNugetPackages ``` -------------------------------- ### Initialize Avalonia UI Controls (C#) Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/DataTemplates.txt This C# code snippet demonstrates the InitializeComponent method within an Avalonia View. It is responsible for finding and assigning UI elements, such as TextBox and ListBox, declared in XAML or code-behind. The method optionally loads XAML markup and relies on Avalonia's name scoping to locate controls. ```csharp // using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace Sample.App { partial class SampleView { [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.TextBox UserNameTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.ListBox NamedListBox; /// /// Wires up the controls and optionally loads XAML markup and attaches dev tools (if Avalonia.Diagnostics package is referenced). /// /// Should the XAML be loaded into the component. [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public void InitializeComponent(bool loadXaml = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } var __thisNameScope__ = this.FindNameScope(); UserNameTextBox = __thisNameScope__?.Find("UserNameTextBox"); NamedListBox = __thisNameScope__?.Find("NamedListBox"); } } } ``` -------------------------------- ### Initialize Avalonia UI Component (C#) Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/ControlWithoutWindow.txt The InitializeComponent method in Avalonia is responsible for setting up the UI elements defined in XAML. This C# code snippet shows how it finds and assigns a TextBox control named 'UserNameTextBox' from the current name scope. It includes an optional parameter to control XAML loading. ```csharp // using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace Sample.App { partial class SampleView { [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.TextBox UserNameTextBox; /// /// Wires up the controls and optionally loads XAML markup and attaches dev tools (if Avalonia.Diagnostics package is referenced). /// /// Should the XAML be loaded into the component. [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public void InitializeComponent(bool loadXaml = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } var __thisNameScope__ = this.FindNameScope(); UserNameTextBox = __thisNameScope__?.Find("UserNameTextBox"); } } } ``` -------------------------------- ### ComStaticPtr Usage for Static COM References Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Illustrates the correct use of ComStaticPtr for static or global COM singletons that must persist for the entire process lifetime. Avoids releasing in the destructor. ```cpp static ComStaticPtr GlDisplay; // correct static IAvnGlDisplay* GlDisplay; // WRONG ``` -------------------------------- ### Configure Project Output for macOS App Bundling Source: https://github.com/avaloniaui/avalonia/blob/master/docs/macos-native.md Shows how to modify a .csproj file to output the build artifacts into a structure that mimics a macOS .app bundle. This is required for certain macOS features like the Accessibility Inspector. ```xml bin\$(Configuration)\$(Platform)\ControlCatalog.NetCore.app/Contents/MacOS false true ``` -------------------------------- ### Initialize Avalonia UI Controls and Load XAML (C#) Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/AttachedPropsWithDevTools.txt The InitializeComponent method in Avalonia is responsible for wiring up UI controls defined in XAML and loading the XAML markup. It optionally attaches developer tools in debug builds. This method is typically auto-generated and should not be modified directly. ```csharp // using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace Sample.App { partial class SampleView { [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.TextBox UserNameTextBox; /// /// Wires up the controls and optionally loads XAML markup and attaches dev tools (if Avalonia.Diagnostics package is referenced). /// /// Should the XAML be loaded into the component. /// Should the dev tools be attached. [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public void InitializeComponent(bool loadXaml = true, bool attachDevTools = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } #if DEBUG if (attachDevTools) { this.AttachDevTools(); } #endif var __thisNameScope__ = this.FindNameScope(); UserNameTextBox = __thisNameScope__?.Find("UserNameTextBox"); } } } ``` -------------------------------- ### Initialize Avalonia UI Controls in C# Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/xNamedControls.txt This C# code snippet demonstrates the `InitializeComponent` method within an Avalonia application. It is responsible for loading XAML markup and finding/assigning UI controls such as `TextBox` and `Button` to their corresponding variables. This method is auto-generated and should not be manually modified. ```csharp // using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace Sample.App { partial class SampleView { [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.TextBox UserNameTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.TextBox PasswordTextBox; [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] internal global::Avalonia.Controls.Button SignUpButton; /// /// Wires up the controls and optionally loads XAML markup and attaches dev tools (if Avalonia.Diagnostics package is referenced). /// /// Should the XAML be loaded into the component. [global::System.CodeDom.Compiler.GeneratedCode("Avalonia.Generators.NameGenerator.InitializeComponentCodeGenerator", "$GeneratorVersion")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public void InitializeComponent(bool loadXaml = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } var __thisNameScope__ = this.FindNameScope(); UserNameTextBox = __thisNameScope__?.Find("UserNameTextBox"); PasswordTextBox = __thisNameScope__?.Find("PasswordTextBox"); SignUpButton = __thisNameScope__?.Find("SignUpButton"); } } } ``` -------------------------------- ### Move Resources from Styles.Resources to ResourceDictionary Source: https://github.com/avaloniaui/avalonia/wiki/Porting-to-Control-Themes Illustrates moving resources defined within `` to become direct children of the root ``. This consolidates resource definitions for Control Themes. ```xml 12,9,12,12 ``` ```xml 12,9,12,12 ``` -------------------------------- ### Build to Local NuGet Cache (Nuke) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds AvaloniaUI NuGet packages and pushes them directly into the local NuGet cache using the `BuildToNuGetCache` target. It's useful for development as it automatically updates packages in the cache. The packages are typically versioned as `9999.0.0-localbuild`. ```bash nuke --target BuildToNuGetCache --configuration Release ``` -------------------------------- ### Set AvaloniaUI Nightly Feed as RestoreSources in Directory.Build.props Source: https://github.com/avaloniaui/avalonia/wiki/Using-nightly-build-feed This XML snippet demonstrates how to configure the AvaloniaUI nightly feed using the `RestoreSources` property within a `Directory.Build.props` file. This method integrates the nightly feed directly into the MSBuild build process, ensuring that packages from this source are considered during restoration. ```xml https://nuget-feed-nightly.avaloniaui.net/v3/index.json; ``` -------------------------------- ### Build NuGet Packages with Specific Version (Nuke) Source: https://github.com/avaloniaui/avalonia/blob/master/docs/nuget.md This command builds AvaloniaUI NuGet packages and forces a specific version using the Nuke global tool. It utilizes the `--force-nuget-version` parameter to set the package version. ```bash nuke CreateNugetPackages --force-nuget-version 11.4.0 ``` -------------------------------- ### ReactiveUI Code-Behind Bindings with Generated Properties Source: https://github.com/avaloniaui/avalonia/blob/master/src/tools/Avalonia.Generators/README.md Illustrates using the generated typed properties (e.g., `UserNameValidation`, `PasswordValidation`) with ReactiveUI for code-behind data binding. This showcases how the source generator facilitates cleaner and more maintainable binding logic by providing direct access to UI elements. ```csharp // UserNameValidation and PasswordValidation are auto generated. public partial class SignUpView : ReactiveWindow { public SignUpView() { InitializeComponent(); this.WhenActivated(disposables => { this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text) .DisposeWith(disposables); }); } } ``` -------------------------------- ### Define Test Method Naming Conventions in C# Source: https://github.com/avaloniaui/avalonia/blob/master/CONTRIBUTING.md Standardizes the naming convention for unit and render tests in Avalonia using a descriptive sentence style separated by underscores. ```csharp void Calling_Foo_Should_Increment_Bar() { // Test logic here } void Rectangle_2px_Stroke_Filled() { // Render test logic here } ``` -------------------------------- ### InitializeComponent for Avalonia UI Views Source: https://github.com/avaloniaui/avalonia/blob/master/tests/Avalonia.Generators.Tests/InitializeComponent/GeneratedInitializeComponent/CustomControls.txt This method is automatically generated to wire up XAML controls to class fields. It uses the AvaloniaXamlLoader to load the UI definition and the NameScope to resolve control references by their names. ```csharp public void InitializeComponent(bool loadXaml = true) { if (loadXaml) { AvaloniaXamlLoader.Load(this); } var __thisNameScope__ = this.FindNameScope(); ClrNamespaceColorPicker = __thisNameScope__?.Find("ClrNamespaceColorPicker"); UriColorPicker = __thisNameScope__?.Find("UriColorPicker"); UserNameTextBox = __thisNameScope__?.Find("UserNameTextBox"); } ``` -------------------------------- ### Define Info.plist for macOS App Bundle Source: https://github.com/avaloniaui/avalonia/blob/master/docs/macos-native.md Provides a template for an Info.plist file required inside an app bundle's Contents directory. It specifies essential application metadata such as the bundle identifier, executable name, and principal class. ```xml CFBundleName ControlCatalog.NetCore CFBundleDisplayName ControlCatalog.NetCore CFBundleIdentifier ControlCatalog.NetCore CFBundleVersion 0.10.999 CFBundlePackageType AAPL CFBundleSignature ???? CFBundleExecutable ControlCatalog.NetCore CFBundleIconFile ControlCatalog.NetCore.icns CFBundleShortVersionString 0.1 NSPrincipalClass NSApplication NSHighResolutionCapable ``` -------------------------------- ### ComObjectWeakPtr Usage for Non-Owning References Source: https://github.com/avaloniaui/avalonia/blob/master/native/Avalonia.Native/README.md Shows the correct use of ComObjectWeakPtr for non-owning references to COM objects, preventing lifetime extension. Access weak references using tryGet(). ```cpp ComObjectWeakPtr _parent; // correct WindowBaseImpl* _parent; // WRONG ``` ```cpp auto parent = _parent.tryGet(); if (parent) { parent->DoSomething(); } ``` -------------------------------- ### Configure AvaloniaUI Nightly NuGet Feed in nuget.config Source: https://github.com/avaloniaui/avalonia/wiki/Using-nightly-build-feed This XML configuration snippet shows how to add the AvaloniaUI nightly build feed to your nuget.config file. It includes clearing existing sources and adding both the official NuGet feed and the nightly feed. This allows your project to restore packages from the latest AvaloniaUI development builds. ```xml ```