### Create and Configure NumberBox in C#
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Instantiate and configure a NumberBox programmatically in C#. This example shows setting properties like header, range, value, and enabling expression input.
```csharp
NumberBox nb = new NumberBox
{
Header = "Font size",
Minimum = 8,
Maximum = 72,
Value = 14,
SmallChange = 1,
LargeChange = 4,
IsWrapEnabled = false,
AcceptsExpression = true, // user can type "12 + 4"
SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Compact,
ValidationMode = NumberBoxValidationMode.InvalidInputOverwritten
};
nb.ValueChanged += (s, e) =>
Console.WriteLine($"Old: {e.OldValue} New: {e.NewValue}");
```
--------------------------------
### NavigationView Control Setup (XAML)
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Configure a NavigationView control with menu items, pane settings, and navigation frame. Supports hierarchical items, headers, and separators.
```xml
```
--------------------------------
### Using StandardUICommand in CommandBar
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/StandardUICommand.xaml.txt
Integrate StandardUICommand into a CommandBar's primary and secondary commands. This example shows a 'Add' button and uses a static resource for the 'DeleteCommand'.
```xaml
```
--------------------------------
### Untargeted TeachingTip Example
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TeachingTip2.xaml.txt
This XAML defines an untargeted TeachingTip. It can be shown programmatically or via a button click.
```XAML
```
--------------------------------
### TaskDialog with Progress Bar and Dynamic Updates
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TaskDialog2.cs.txt
This snippet shows how to initialize a TaskDialog with a progress bar, set its content, and handle the Opened event to start a background task. The background task simulates a download, updating the progress bar and dialog content based on simulated network conditions. It uses Dispatcher.UIThread.Post to update the UI from the background thread and finally closes the dialog with an OK result.
```csharp
var td = new TaskDialog
{
Title = "FluentAvalonia",
ShowProgressBar = true,
IconSource = new SymbolIconSource { Symbol = Symbol.Download },
SubHeader = "Downloading",
Content = "Please wait while your file downloads",
Buttons =
{
TaskDialogButton.CancelButton
}
};
td.Opened += async (s, e) =>
{
// We immediately begin the progress task as soon as the dialog opens
// NOTE: Cancelling the dialog while this is running won't stop this this async process, you should
// use a CancellationToken and monitor the dialog result to cancel this task
await Task.Run(async () =>
{
int progress = 0;
TaskDialogProgressState state = TaskDialogProgressState.Normal;
int delay = 100;
while (progress < 100)
{
await Task.Delay(delay);
progress++;
if (progress == 50)
{
state = TaskDialogProgressState.Indeterminate | TaskDialogProgressState.Suspended;
// If you update the TaskDialog - remember we're not on the UI Thread, post via dispatcher
Dispatcher.UIThread.Post(() => { td.Content = "Experiencing network connectivitiy issues. Download speed reduced"; });
delay = 1000;
}
else if (progress == 60)
{
state = TaskDialogProgressState.Normal;
Dispatcher.UIThread.Post(() => { td.Content = "All good. Resuming normal downloading."; });
delay = 100;
}
// This automatically does UIThread invoking, so just call this normally
td.SetProgressBarState(progress, state);
}
// All done, auto close the dialog here
Dispatcher.UIThread.Post(() => { td.Hide(TaskDialogStandardResult.OK); });
});
};
// Don't forget to set the XamlRoot!!
td.XamlRoot = VisualRoot;
var result = await td.ShowAsync();
```
--------------------------------
### Declare StandardUICommand as a Resource
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/StandardUICommand.xaml.txt
Declare the Command as a resource so it can be shared across multiple UI elements. This example uses the 'Delete' kind and binds to a 'DeleteItem' command.
```xaml
```
--------------------------------
### Wrap IconSource in IconSourceElement
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Use IconSourceElement to host any IconSource type, allowing it to be used as a control. This example wraps a SymbolIconSource.
```xml
```
--------------------------------
### Basic CommandBar with Primary and Secondary Commands
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/CommandBar3.xaml.txt
This snippet shows a basic CommandBar setup with primary commands like Save and Undo, and secondary commands including Cut, Copy, Paste, and toggle buttons for Bold, Italic, and Underline. The DefaultLabelPosition is set to Right.
```XAML
```
--------------------------------
### TabView Control Example
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TabView3.xaml.txt
This XAML defines a TabView control with several TabViewItems. It showcases basic configuration like tab width, close button overlay, and header/footer content. Event handlers for adding and closing tabs are also specified.
```XAML
```
--------------------------------
### Define CommandBarFlyout with Primary and Secondary Commands
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/CommandBarFlyout.xaml.txt
Define a CommandBarFlyout with primary commands directly as XML content and secondary commands within a SecondaryCommands tag. This setup is useful for creating contextual menus.
```xaml
```
--------------------------------
### Format NumberBox Input
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/NumberBox3.cs.txt
Assign a custom lambda expression to the NumberFormatter property to control how input is displayed. This example formats the input to two decimal places.
```csharp
var nm = this.FindControl("FormattedNumBox");
nm.NumberFormatter = (input) =>
{
double increment = 1/0.25;
return (Math.Round(input * increment, MidpointRounding.AwayFromZero) / increment).ToString("F2");
};
```
--------------------------------
### Basic SettingsExpander with Items
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander2.xaml.txt
Demonstrates a SettingsExpander with a header, icon, description, and multiple SettingsExpanderItems. Some items include descriptions and one has a footer with a Button.
```XAML
```
--------------------------------
### Basic TabView Implementation
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TabView1.xaml.txt
Demonstrates the basic structure of a TabView control, including binding to a collection of documents and defining a template for each tab item.
```XAML
```
--------------------------------
### Declare and Show TaskDialog in C#
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TaskDialog1.cs.txt
Programmatically create a TaskDialog instance in C#. Ensure to set the XamlRoot property before showing the dialog. If VisualRoot is a Window, it launches in windowed mode; otherwise, it attempts hosted mode.
```csharp
var td = new TaskDialog
{
// Title property only applies on Windowed dialogs
Title = "FluentAvalonia",
Header = "Header",
Subheader = "Subheader",
Content = "This is some sample text, but you can put more advanced content here if you like",
IconSource = new SymbolIconSource { Symbol = Symbol.Save },
FooterVisibility = TaskDialogFooterVisibility.Auto,
Footer = new CheckBox { Content = "Never show me this again" },
Commands =
{
new TaskDialogCommand
{
Text = "Command Text",
Description = "Description",
DialogResult = "CommandResult",
// ClosesOnInvoked property lets you choose if invoking this command closes the dialog
// automatically (default true)
ClosesOnInvoked = true,
// Can also set IconSource
// Can also set IsEnabled
}
},
Buttons =
{
// For more advanced scenarios, you can create your own buttons
// Custom buttons allow you to attach icons, custom results,
// command and click handlers to fully customize your experience
// Note: 'null' is not a valid dialog result and is automatically
// converted to TaskDialogStandardResult.None when the dialog closes
new TaskDialogButton("OK" /* text */, "myResult" /* dialogResult */)
// There are some default buttons for simple cases provided
// These have predefinded text and results that correspond to
// TaskDialogStandardResult enum
// Note that built in buttons cannot have Commands, Icons, or
// click handlers attached to them
TaskDialogButton.OKButton,
TaskDialogButton.CancelButton,
TaskDialogButton.YesButton,
TaskDialogButton.NoButton,
TaskDialogButton.RetryButton,
TaskDialogButton.CloseButton
}
};
// Before showing a dialog declared in C#, you MUST set the XamlRoot property
// Using the VisualRoot is fine, if the VisualRoot is a Window, the dialog automatically launches in
// Windowed mode, otherwise, it tries to find the OverlayLayer and will launch in hosted mode
// If your TaskDialog is declared in Xaml, this is automatically handled for you
td.XamlRoot = this.VisualRoot;
var result = await td.ShowAsync();
```
--------------------------------
### Basic TeachingTip Implementation
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TeachingTip1.xaml.txt
Use this snippet to display a TeachingTip anchored to another control. Ensure the target control is properly referenced.
```XAML
```
--------------------------------
### Create TaskDialog in FluentAvalonia
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Illustrates the creation of an enhanced TaskDialog with various elements like title, header, content, buttons, commands, and a footer. Shows how to display it attached to a window.
```csharp
var td = new TaskDialog
{
Title = "App Update",
Header = "Version 3.0 is available",
SubHeader = "Would you like to install it now?",
IconSource = new SymbolIconSource { Symbol = Symbol.Important },
Content = "The update includes critical security fixes.",
Buttons =
{
new TaskDialogButton("Update now", TaskDialogStandardResult.OK),
new TaskDialogButton("Remind later", TaskDialogStandardResult.Cancel)
},
Commands =
{
new TaskDialogCommand
{
Text = "View release notes",
Description = "Opens the browser",
IconSource = new SymbolIconSource { Symbol = Symbol.Globe }
}
},
Footer = "Automatic updates are enabled in Settings.",
FooterVisibility = TaskDialogFooterVisibility.Auto
};
td.Closing += (sender, e) =>
{
if (e.Result is TaskDialogStandardResult r)
Console.WriteLine($"Result: {r}");
};
// Show attached to a window
object result = await td.ShowAsync(parentWindow);
```
--------------------------------
### Initialize and Show CommandBarFlyout
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/CommandBarFlyout.cs.txt
Listens for ContextRequested event to show the flyout. Handles transient vs. standard display modes.
```csharp
// We rely on code behind to show the flyout
// Listen for the ContextRequested event so we can change the launch behavior based on whether it was a
// left or right click.
this.FindControl("myImageButton").ContextRequested += OnMyImageButtonContextRequested;
private void MyImageButton_Click(object sender, RoutedEventArgs args)
{
ShowMenu(true);
}
private void OnMyImageButtonContextRequested(object sender, ContextRequestedEventArgs e)
{
ShowMenu(false);
e.Handled = true;
}
private void ShowMenu(bool isTransient)
{
var flyout = Resources["CommandBarFlyout1"] as CommandBarFlyout;
flyout.ShowMode = isTransient ? FlyoutShowMode.Transient : FlyoutShowMode.Standard;
flyout.ShowAt(this.FindControl("Image1"));
}
```
--------------------------------
### Using Color2 for Color Representation and Conversion
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Demonstrates constructing Color2 from RGBA bytes or Avalonia Color, accessing color channels, performing color space conversions (HSV, HSL), and adjusting lightness. Also shows round-tripping back to Avalonia Color and implicit conversion.
```csharp
using FluentAvalonia.UI.Media;
using Avalonia.Media;
// Construct from RGBA bytes
var red = new Color2(255, 0, 0);
// Construct from Avalonia Color
var avColor = Color.Parse("#0078D4");
Color2 c = new Color2(avColor);
// Channel access
Console.WriteLine($"R={c.R} G={c.G} B={c.B} A={c.A}");
Console.WriteLine($"Hue={c.Hue}° Saturation={c.Saturationf:F2} Value={c.Valuef:F2}");
// Color space conversion
Color2 hsv = c.ToHSV();
Color2 hsl = c.ToHSL();
// Lighten / darken (used by accent color generation)
Color2 lighter = c.LightenPercent(0.20f); // +20 % lightness
Color2 darker = c.LightenPercent(-0.30f); // -30 % lightness
// Round-trip back to Avalonia Color
Color avResult = (Color)lighter;
// Implicit from Avalonia Color
Color2 implicit = avColor; // implicit operator
```
--------------------------------
### Basic SettingsExpander Usage
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander3.xaml.txt
Demonstrates the basic usage of the SettingsExpander control with a header and icon source, bound to an ItemsSource.
```XAML
```
--------------------------------
### Navigate to a Page
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.cs.txt
Use this to navigate to a new page. Ensure the page derives from IControl.
```csharp
TestFrame.Navigate(typeof(SamplePage));
```
--------------------------------
### Control InfoBar Programmatically in FluentAvalonia
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Demonstrates how to programmatically control the visibility, severity, and content of an InfoBar. Includes listening for closing events.
```csharp
// Show a persistent error bar programmatically
ErrorBar.IsOpen = true;
ErrorBar.Severity = InfoBarSeverity.Error;
ErrorBar.Title = "Connection failed";
ErrorBar.Message = "Check your network and try again.";
ErrorBar.IsClosable = false;
// Listen for close events
ErrorBar.Closing += (bar, e) =>
{
if (e.Reason == InfoBarCloseReason.CloseButton)
Console.WriteLine("User dismissed the bar");
};
ErrorBar.Closed += (bar, e) => ErrorBar.IsOpen = false;
```
--------------------------------
### Navigate to a Page with a Parameter
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.cs.txt
Navigate to a page and pass a parameter to it. The parameter can be any object.
```csharp
TestFrame.Navigate(typeof(SamplePage), paramHere);
```
--------------------------------
### TeachingTip with Hero Content
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TeachingTip3.xaml.txt
Configure a TeachingTip with a title, subtitle, action button, close button, and hero content. The hero content is an image displayed at the top of the tip.
```XAML
```
--------------------------------
### Go Forward in Navigation
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.cs.txt
Navigate forward to the next page in the navigation history. A custom transition can be applied.
```csharp
TestFrame.GoForward();
```
```csharp
TestFrame.GoForward(transitionInfo); //With custom transtion info
```
--------------------------------
### Configure FluentAvaloniaTheme at Runtime (C#)
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Set custom accent colors or force theme variants programmatically. Ensure the theme is cast to FluentAvaloniaTheme before modification. Use `null` to restore system accent color.
```csharp
if (App.Current.Styles[0] is FluentAvaloniaTheme fat)
{
fat.CustomAccentColor = Color.Parse("#0078D4");
// Restore system accent: fat.CustomAccentColor = null;
}
// Force a specific theme variant
Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
// Or use HighContrastTheme:
Application.Current.RequestedThemeVariant = FluentAvaloniaTheme.HighContrastTheme;
```
--------------------------------
### Initialize AppWindow with Custom Splash Screen
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/AppWindow2.cs.txt
Assign a custom splash screen implementation to the SplashScreen property in the AppWindow constructor. The splash screen will be displayed automatically when the window opens.
```csharp
public class MainWindow : AppWindow
{
public MainWindow()
{
InitializeComponent();
// Set your splash screen and the rest is taken care of when you open the window
SplashScreen = new SampleAppSplashScreen();
}
// NOTE: If you override OnOpened for custom logic, be sure to call base.OnOpened() FIRST
// as that allows the SplashScreen to run which will hold the loading of window content
// until it finishes (unless you must run something first).
protected override void OnOpened()
{
base.OnOpened();
}
}
```
--------------------------------
### Go Back in Navigation
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.cs.txt
Navigate back to the previous page in the navigation history. A custom transition can be applied.
```csharp
TestFrame.GoBack();
```
```csharp
TestFrame.GoBack(transitionInfo); //With custom transition info
```
--------------------------------
### Navigate with FluentAvalonia Frame
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Demonstrates navigation to different pages, including passing parameters and using custom transitions. Handles back/forward navigation and lifecycle events.
```csharp
// XAML:
// Navigate to a page type
AppFrame.Navigate(typeof(DetailPage));
// Navigate with a parameter and a slide animation
AppFrame.Navigate(
typeof(DetailPage),
parameter: new ItemViewModel { Id = 42 },
infoOverride: new SlideNavigationTransitionInfo
{
Effect = SlideNavigationTransitionEffect.FromRight
});
// Navigate using NavigationPageFactory (ViewModel-first pattern)
AppFrame.NavigationPageFactory = new MyPageFactory();
AppFrame.Navigate(typeof(DetailViewModel), parameter: myVm);
// Back/forward
if (AppFrame.CanGoBack) AppFrame.GoBack();
if (AppFrame.CanGoForward) AppFrame.GoForward();
// Handle page lifecycle via routed events on the UserControl/Page
AddHandler(Frame.NavigatedToEvent, (s, e) =>
{
var param = e.Parameter; // object passed from Navigate()
var mode = e.NavigationMode; // New, Back, Forward, Refresh
});
AddHandler(Frame.NavigatingFromEvent, (s, e) =>
{
if (HasUnsavedChanges)
e.Cancel = true; // abort navigation
});
```
--------------------------------
### Basic Frame Usage with Navigation Buttons
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.xaml.txt
Demonstrates how to integrate the Frame control with buttons for navigation. The 'GoBack' and 'GoForward' commands are bound to the Frame's navigation methods, and their enabled states are controlled by 'CanGoBack' and 'CanGoForward' properties.
```XAML
```
--------------------------------
### Display ContentDialog in FluentAvalonia
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Shows how to create and display a modal ContentDialog with customizable buttons and asynchronous confirmation. Supports deferral-based cancellation.
```csharp
var dialog = new ContentDialog
{
Title = "Delete file?",
Content = "This action cannot be undone.",
PrimaryButtonText = "Delete",
SecondaryButtonText = "Move to Recycle Bin",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Close,
IsPrimaryButtonEnabled = true
};
// Cancellable via deferral
dialog.PrimaryButtonClick += async (d, args) =>
{
var deferral = args.GetDeferral();
bool ok = await ConfirmDeletionAsync();
if (!ok) args.Cancel = true;
deferral.Complete();
};
dialog.Closing += (d, args) =>
{
if (args.Result == ContentDialogResult.Primary)
Console.WriteLine("Primary confirmed");
};
ContentDialogResult result = await dialog.ShowAsync();
// result: Primary | Secondary | None (close/escape)
```
--------------------------------
### TabView Implementation
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Defines a TabView with initial tabs and configures tab behavior. Use this to create a tabbed interface.
```xml
```
--------------------------------
### Navigate to a Page with Custom Animation
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame.cs.txt
Navigate to a page with a custom transition animation. Supported animations include Slide, Entrance, DrillIn, and Suppress.
```csharp
TestFrame.Navigate(typeof(SamplePage), paramHere, transitionInfo);
```
--------------------------------
### Basic Range Slider Configuration
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/RangeSlider1.xaml.txt
Configure a Range Slider with minimum, maximum, step frequency, and tooltip visibility using XAML.
```XAML
```
--------------------------------
### Navigate Using Object Instance
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame3.cs.txt
Use the NavigateFromObject method to navigate to a page by passing a ViewModel instance. This method relies on the GetPageFromObject implementation in your custom factory. Note that this method does not support passing parameters.
```csharp
// To navigate by passing a data context use the NavigateFromObject method
// Note: NavigateFromObject does not allow passing in parameters, as the viewmodel should
// contain all the information you need, unlike the default logic that uses a Type
// and Activator.CreateInstance
// This is for demo purposes, but to ensure Frame's caching logic works correctly, be sure
// to store a reference to this view model and pass that instance everytime you want to
// navigate to that page
var viewModel = new MyViewModel1();
MyFrame.NavigateFromObject(viewModel);
```
--------------------------------
### InfoBadge Styles
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/InfoBadge2.xaml.txt
Demonstrates different visual styles for InfoBadges including icon, value, and dot indicators for various states.
```XAML
```
--------------------------------
### Display BitmapIcon from URI
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Load and display a BitmapIcon from a specified URI source. Set ShowAsMonochrome to true if the icon should be rendered in a single color.
```xml
```
--------------------------------
### BreadcrumbBar2 Initialization and Event Handling
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Breadcrumb2.cs.txt
Initializes the BreadcrumbBar2 with a collection of folders and sets up event handlers for item clicks and a reset button. The ItemClicked event handler modifies the ItemsSource to reflect the selected path.
```csharp
_folderList = new ObservableCollection
{
new BreadcrumbFolder("Home"),
new BreadcrumbFolder("Folder1"),
new BreadcrumbFolder("Folder2"),
new BreadcrumbFolder("Folder3"),
};
// Make a copy of the folders for the ItemsSource so we preserve the original
BreadcrumbBar2.ItemsSource = new ObservableCollection(_folderList);
BreadcrumbBar2.ItemClicked += BreadcrumbBar2ItemClicked;
ResetSampleButton.Click += ResetSampleButtonClick;
```
--------------------------------
### CommandBar with Primary and Secondary Commands
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/CommandBar1.xaml.txt
This snippet demonstrates how to define primary and secondary commands within a CommandBar. Use primary commands for frequently used actions and secondary commands for less frequent ones.
```XAML
```
--------------------------------
### Basic FAMenuFlyout with Various Items
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/MenuFlyout.xaml.txt
This snippet shows how to define a FAMenuFlyout attached to a Button, including standard items, separators, submenus, toggle items, and radio menu items.
```XAML
```
--------------------------------
### Basic CommandBar with Primary and Secondary Commands
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/CommandBar2.xaml.txt
This snippet shows how to define a CommandBar with both primary and secondary command sets. Primary commands are typically displayed prominently, while secondary commands are accessible via an overflow menu.
```XAML
```
--------------------------------
### Basic NavigationView with Menu Items
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/NavView1.xaml.txt
Defines a NavigationView with a left pane and several menu items, each with content, a tag, and an icon source.
```XAML
```
--------------------------------
### TaskDialog with Progress Bar and Deferral
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TaskDialog3.cs.txt
Use the Closing event to grab a deferral for asynchronous operations like updating a progress bar. Ensure XamlRoot is set before showing the dialog.
```csharp
var td = new TaskDialog
{
Title = "FluentAvalonia",
ShowProgressBar = false,
Content = "Are you sure you want to delete the file?\n" +
"../Directory/One/file.txt",
Buttons =
{
TaskDialogButton.YesButton,
TaskDialogButton.NoButton
}
};
// Use the closing event to grab a deferral
// You can also cancel closing here if you like
td.Closing += (s, e) =>
{
// We only want to use the deferral on the 'Yes' Button
if ((TaskDialogStandardResult)e.Result == TaskDialogStandardResult.Yes)
{
var deferral = e.GetDeferral();
td.ShowProgressBar = true;
int value = 0;
DispatcherTimer timer = null;
void Tick(object s, EventArgs e)
{
td.SetProgressBarState(++value, TaskDialogProgressState.Normal);
if (value == 100)
{
timer.Stop();
// Call this when you're done. It will signal the dialog to resume closing
deferral.Complete();
}
}
timer = new DispatcherTimer(TimeSpan.FromMilliseconds(75), DispatcherPriority.Normal, Tick);
timer.Start();
}
};
// Don't forget to set the XamlRoot!!
td.XamlRoot = VisualRoot;
_ = await td.ShowAsync();
```
--------------------------------
### Basic FAMenuFlyout Usage
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/MenuFlyout2.xaml.txt
Attaches a FAMenuFlyout to a Button, populating it with items from a bound collection.
```XAML
```
--------------------------------
### SettingsExpanderPageViewModel Initialization
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander3.cs.txt
Initializes the ViewModel with a list of settings items, including RecentImagesSettingsItem and FooterButtonSettingsItem. This sets up the data structure for the settings expander UI.
```csharp
public class SettingsExpanderPageViewModel : ViewModelBase
{
public SettingsExpanderPageViewModel()
{
Items = new List
{
new RecentImagesSettingsItem()
{
Header = "Recent images",
},
new FooterButtonSettingsItem()
{
Header = "Choose a photo"
}
};
}
public List Items { get; }
}
```
--------------------------------
### Configure InfoBar in FluentAvalonia (XAML)
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Defines an InfoBar using XAML with a title, message, severity, and an action button. The bar is initially open and closable by the user.
```xml
```
--------------------------------
### Initialize FAComboBox with Items
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/FAComboBox.cs.txt
This code initializes a ViewModel with a list of ComboItem objects to be used in an FAComboBox. Ensure the ComboItem class has a DisplayName property for display.
```csharp
public class FAComboBoxPageViewModel : ViewModelBase
{
public FAComboBoxPageViewModel()
{
Items = new List
{
new ComboItem("Red"),
new ComboItem("Orange"),
new ComboItem("Yellow"),
new ComboItem("Green"),
new ComboItem("Blue"),
new ComboItem("Indigo"),
new ComboItem("Violet"),
new ComboItem("White"),
new ComboItem("Black"),
};
}
public List Items { get; }
}
public class ComboItem
{
public ComboItem(string name)
{
DisplayName = name;
}
public string DisplayName { get; }
}
```
--------------------------------
### Force TaskDialog Hosted Mode
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/TaskDialog1.cs.txt
To explicitly launch a TaskDialog in hosted mode, pass 'true' as an argument to the ShowAsync method. This overrides the default behavior based on XamlRoot.
```csharp
var result = await td.ShowAsync(true);
```
--------------------------------
### CommandBar Layout
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Configures a CommandBar with primary and secondary commands, setting the default label position to Bottom. Use for toolbars with primary and overflow actions.
```xml
```
--------------------------------
### SettingsExpanderItem with Image Gallery
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander3.xaml.txt
Shows how to define a DataTemplate for a SettingsExpanderItem to display a header and a horizontal list of images.
```XAML
```
--------------------------------
### Define and Use XamlUICommand
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/XamlUICommand.xaml.txt
Defines a custom XamlUICommand with an icon, description, label, and hotkey, then assigns it to a CommandBarButton.
```XAML
```
--------------------------------
### Page Navigation Event Handlers
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame2.cs.txt
Implement methods to handle the navigation events. These methods correspond to the WinUI Page virtual methods for navigation lifecycle.
```csharp
private void OnNavigatingFrom(object sender, NavigatingCancelEventArgs args) { }
private void OnNavigatedFrom(object sender, NavigationEventArgs args) { }
private void OnNavigatedTo(object sender, NavigationEventArgs args) { }
```
--------------------------------
### Navigate Using Type
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/Frame3.cs.txt
Navigate to a page using its Type with the standard Navigate method. This approach requires that the GetPage(Type) method in your custom INavigationFactory is implemented to handle type-based navigation.
```csharp
// If you still want to navigate via a Type, be sure that GetPage(Type) in your navigation
// factory is implemented and use the regular methods, such as Navigate(). A custom
// INavigationFactory takes precedence over the default logic.
MyFrame.Navigate(typeof(SettingsPage));
```
--------------------------------
### SettingsExpander with Slider
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander1.xaml.txt
This snippet shows how to use SettingsExpander with a Slider in its footer.
```XAML
```
--------------------------------
### Configure FontIconSource in C#
Source: https://context7.com/amwx/fluentavalonia/llms.txt
Programmatically create a FontIconSource, specifying the glyph, font family, and font size. This offers granular control over font-based icons.
```csharp
// FontIconSource
var fontIcon = new FontIconSource
{
Glyph = "\uE72D",
FontFamily = new FontFamily("Segoe MDL2 Assets"),
FontSize = 18
};
```
--------------------------------
### Base Settings Item Class
Source: https://github.com/amwx/fluentavalonia/blob/master/samples/FAControlsGallery/Pages/SampleCode/SettingsExpander3.cs.txt
Defines the base class for all settings items, providing a common Header property. This serves as a foundation for more specific settings item types.
```csharp
public class SettingsItemBase
{
public string Header { get; set; }
}
```