### ProgressRing Configuration Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Example of how to configure a ProgressRing with animation and size properties.
```xaml
```
--------------------------------
### Styling Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/ProgressRing.md
Example of how to style the ProgressRing control.
```xaml
```
--------------------------------
### Dialog Coordinator Setup
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/errors.md
Example of setting up DialogParticipation with a DialogCoordinator in MVVM.
```csharp
// In View
public partial class MyView : UserControl
{
public MyView()
{
InitializeComponent();
DialogParticipation.SetRegister(this, new DialogCoordinator());
}
}
// In ViewModel
public class MyViewModel
{
private readonly IDialogCoordinator _dialogCoordinator;
public MyViewModel(IDialogCoordinator dialogCoordinator)
{
_dialogCoordinator = dialogCoordinator;
}
public async Task ShowDialog()
{
await _dialogCoordinator.ShowMessageAsync(this, "Title", "Message");
}
}
```
--------------------------------
### ViewModel Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Tile.md
Example ViewModel for the dynamic tile.
```csharp
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media;
public class DashboardViewModel : INotifyPropertyChanged
{
private string _tileTitle;
private string _tileCount;
private int _tileWidth;
private int _tileHeight;
private Brush _tileBackground;
public string TileTitle
{
get => _tileTitle;
set
{
if (_tileTitle != value)
{
_tileTitle = value;
OnPropertyChanged(nameof(TileTitle));
}
}
}
public string TileCount
{
get => _tileCount;
set
{
if (_tileCount != value)
{
_tileCount = value;
OnPropertyChanged(nameof(TileCount));
}
}
}
public int TileWidth
{
get => _tileWidth;
set
{
if (_tileWidth != value)
{
_tileWidth = value;
OnPropertyChanged(nameof(TileWidth));
}
}
}
public int TileHeight
{
get => _tileHeight;
set
{
if (_tileHeight != value)
{
_tileHeight = value;
OnPropertyChanged(nameof(TileHeight));
}
}
}
public Brush TileBackground
{
get => _tileBackground;
set
{
if (_tileBackground != value)
{
_tileBackground = value;
OnPropertyChanged(nameof(TileBackground));
}
}
}
public ICommand TileClickedCommand { get; }
public DashboardViewModel()
{
TileTitle = "Tasks";
TileCount = "7";
TileWidth = 150;
TileHeight = 150;
TileBackground = new SolidColorBrush(Colors.Blue);
TileClickedCommand = new RelayCommand(OnTileClicked);
}
private void OnTileClicked()
{
// Handle tile click
System.Diagnostics.Debug.WriteLine($"Tile '{TileTitle}' clicked");
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
```
--------------------------------
### Flyout Configuration Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Example of how to configure a Flyout with position, theme, and animation properties.
```xaml
```
--------------------------------
### ToggleSwitch Configuration Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Example of how to configure a ToggleSwitch with various properties.
```xaml
```
--------------------------------
### MetroWindow Configuration Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Example of how to configure a MetroWindow with title bar, button, and flyout settings.
```xaml
```
--------------------------------
### ToString Method Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/HotKeyBox.md
Example demonstrating the output of the ToString() method for different hotkey combinations.
```text
- "Ctrl+S"
- "Ctrl+Shift+Delete"
- "Alt+F4"
```
--------------------------------
### App.xaml Theme Setup
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Example of how to set a MahApps.Metro theme in App.xaml.
```xaml
```
--------------------------------
### Tile Sizing
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Tile.md
Examples of different tile sizes.
```xaml
```
--------------------------------
### Example with Methods
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/NumericUpDown.md
Example of using the programmatic change methods in response to button clicks.
```csharp
private void IncreaseValue_Click(object sender, RoutedEventArgs e)
{
numericUpDown.MoveUp();
}
private void DecreaseValue_Click(object sender, RoutedEventArgs e)
{
numericUpDown.MoveDown();
}
private void SetToMax_Click(object sender, RoutedEventArgs e)
{
numericUpDown.MoveToMaximum();
}
```
--------------------------------
### MetroHeader Example
Source: https://github.com/mahapps/mahapps.metro/wiki/Release-1.6.0
Example of how to use the new MetroHeader control with a custom header template.
```XAML
```
--------------------------------
### ViewModel Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/HotKeyBox.md
Example ViewModel demonstrating how to use the HotKey class to manage and register hotkeys.
```csharp
using MahApps.Metro.Controls;
using System.ComponentModel;
using System.Windows.Input;
public class ShortcutsViewModel : INotifyPropertyChanged
{
private HotKey? _openFileHotKey;
private HotKey? _saveFileHotKey;
private HotKey? _exitHotKey;
public HotKey? OpenFileHotKey
{
get => _openFileHotKey;
set
{
if (_openFileHotKey != value)
{
_openFileHotKey = value;
OnPropertyChanged(nameof(OpenFileHotKey));
RegisterHotKey("OpenFile", value);
}
}
}
public HotKey? SaveFileHotKey
{
get => _saveFileHotKey;
set
{
if (_saveFileHotKey != value)
{
_saveFileHotKey = value;
OnPropertyChanged(nameof(SaveFileHotKey));
RegisterHotKey("SaveFile", value);
}
}
}
public HotKey? ExitHotKey
{
get => _exitHotKey;
set
{
if (_exitHotKey != value)
{
_exitHotKey = value;
OnPropertyChanged(nameof(ExitHotKey));
RegisterHotKey("Exit", value);
}
}
}
public ShortcutsViewModel()
{
// Initialize with default shortcuts
OpenFileHotKey = new HotKey(Key.O, ModifierKeys.Control);
SaveFileHotKey = new HotKey(Key.S, ModifierKeys.Control);
ExitHotKey = new HotKey(Key.F4, ModifierKeys.Alt);
}
private void RegisterHotKey(string name, HotKey? hotKey)
{
if (hotKey != null)
{
System.Diagnostics.Debug.WriteLine($"{name}: {hotKey.Key} + {hotKey.Modifiers}");
// Register with global hotkey handler
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
```
--------------------------------
### SerializedKey Property Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/HotKeyBox.md
Example showing how to get a serialized string representation of a HotKey object.
```csharp
var hotkey = new HotKey(Key.S, ModifierKeys.Control);
string serialized = hotkey.SerializedKey; // "Ctrl+S"
```
--------------------------------
### Basic Tile
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Tile.md
An example demonstrating how to create and configure a Tile control in C# code-behind.
```csharp
using MahApps.Metro.Controls;
using System.Windows;
using System.Windows.Input;
namespace MyApp
{
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
var tile = new Tile
{
Title = "Documents",
Count = "5",
Width = 150,
Height = 150,
Background = new SolidColorBrush(Colors.Blue),
Foreground = new SolidColorBrush(Colors.White),
Command = new RelayCommand(() => MessageBox.Show("Tile clicked!"))
};
this.Content = tile;
}
}
}
```
--------------------------------
### LoginDialog Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Dialogs.md
Shows how to use the LoginDialog to get username and password input from the user.
```csharp
var loginData = await this.ShowLoginAsync(
"Authentication",
"Please enter your credentials");
if (loginData != null)
{
string username = loginData.Username;
string password = loginData.Password;
// Process login
}
```
--------------------------------
### MissingRequiredTemplatePartException Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/types.md
Example of throwing MissingRequiredTemplatePartException.
```csharp
if (GetTemplateChild("PART_ContentHost") is not ContentPresenter)
{
throw new MissingRequiredTemplatePartException(this, "PART_ContentHost");
}
```
--------------------------------
### Example Method Usage
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/FlipView.md
Demonstrates how to call the navigation methods of the FlipView control in response to button clicks.
```csharp
private void FirstButton_Click(object sender, RoutedEventArgs e)
{
flipView.GoToFirstSlide();
}
private void PreviousButton_Click(object sender, RoutedEventArgs e)
{
flipView.GoToPreviousSlide();
}
private void NextButton_Click(object sender, RoutedEventArgs e)
{
flipView.GoToNextSlide();
}
private void LastButton_Click(object sender, RoutedEventArgs e)
{
flipView.GoToLastSlide();
}
```
--------------------------------
### Entypo Icon Example
Source: https://github.com/mahapps/mahapps.metro/wiki/Icons
Example of using an Entypo icon from MahApps.Metro.IconPacks.
```xaml
```
--------------------------------
### With Commands
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/ToggleSwitch.md
XAML example illustrating how to bind commands to the ToggleSwitch for state changes.
```xaml
```
--------------------------------
### Basic Toggle
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/ToggleSwitch.md
Example of creating and configuring a ToggleSwitch in C# code.
```csharp
using MahApps.Metro.Controls;
using System.Windows;
namespace MyApp
{
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
var toggle = new ToggleSwitch
{
IsOn = true,
OnContent = "Enabled",
OffContent = "Disabled"
};
this.Content = toggle;
}
}
}
```
--------------------------------
### Confirmation Dialog Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Dialogs.md
Example of a common confirmation dialog pattern.
```csharp
var result = await this.ShowMessageAsync(
"Confirm Deletion",
"Are you sure you want to delete this item?",
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = "Delete",
NegativeButtonText = "Keep"
});
if (result == MessageDialogResult.Affirmative)
{
DeleteItem();
}
```
--------------------------------
### ViewModel Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/ProgressRing.md
Example of a ViewModel that can be used to control the IsLoading property of the ProgressRing.
```csharp
using System.ComponentModel;
using System.Threading.Tasks;
public class DataViewModel : INotifyPropertyChanged
{
private bool _isLoading;
public bool IsLoading
{
get => _isLoading;
set
{
if (_isLoading != value)
{
_isLoading = value;
OnPropertyChanged(nameof(IsLoading));
}
}
}
public async Task LoadDataAsync()
{
IsLoading = true;
try
{
// Simulate long-running operation
await Task.Delay(3000);
}
finally
{
IsLoading = false;
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
```
--------------------------------
### Modern Icon Example
Source: https://github.com/mahapps/mahapps.metro/wiki/Icons
Example of using a Modern UI icon from MahApps.Metro.IconPacks.
```xaml
```
--------------------------------
### Basic Window Setup
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/README.md
Sets up a basic MahApps.Metro window with custom title bar and content.
```xaml
```
--------------------------------
### Material Icon Example
Source: https://github.com/mahapps/mahapps.metro/wiki/Icons
Example of using a Material Design icon from MahApps.Metro.IconPacks.
```xaml
```
--------------------------------
### ProgressDialog Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Dialogs.md
Demonstrates the usage of ProgressDialog, including updating progress, setting messages, and closing the dialog.
```csharp
var controller = await this.ShowProgressAsync(
"Processing",
"Loading files...",
isCancelable: true);
try
{
for (int i = 0; i <= 100; i++)
{
controller.SetProgress(i / 100.0);
controller.SetMessage($"Processing {i}%");
await Task.Delay(100);
}
}
finally
{
await controller.CloseAsync();
}
```
--------------------------------
### MetroDialogSettings Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Dialogs.md
Example of configuring and showing a message dialog with custom settings.
```csharp
var settings = new MetroDialogSettings
{
AffirmativeButtonText = "Yes",
NegativeButtonText = "No",
FirstAuxiliaryButtonText = "Maybe",
ColorScheme = MetroDialogColorScheme.Inverted,
MaximumBodyHeight = 500
};
var result = await this.ShowMessageAsync(
"Question",
"Do you want to continue?",
MessageDialogStyle.AffirmativeAndNegativeAndFirstAuxiliary,
settings);
```
--------------------------------
### With Header and Content
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/ToggleSwitch.md
XAML example demonstrating the use of Header and Content properties, with data binding for IsOn.
```xaml
```
--------------------------------
### Window Placement Settings Implementation
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
An example implementation of the IWindowPlacementSettings interface for saving and loading window position and state.
```csharp
using MahApps.Metro.Controls;
using System.Windows;
public class WindowPlacementSettings : IWindowPlacementSettings
{
public int X
{
get => (int)Properties.Settings.Default.WindowX;
set => Properties.Settings.Default.WindowX = (double)value;
}
public int Y
{
get => (int)Properties.Settings.Default.WindowY;
set => Properties.Settings.Default.WindowY = (double)value;
}
public int Width
{
get => (int)Properties.Settings.Default.WindowWidth;
set => Properties.Settings.Default.WindowWidth = (double)value;
}
public int Height
{
get => (int)Properties.Settings.Default.WindowHeight;
set => Properties.Settings.Default.WindowHeight = (double)value;
}
public WindowState State
{
get => (WindowState)Properties.Settings.Default.WindowState;
set => Properties.Settings.Default.WindowState = (int)value;
}
public void Save()
{
Properties.Settings.Default.Save();
}
public void Reload()
{
Properties.Settings.Default.Reload();
}
}
```
--------------------------------
### Date Range Selector Example
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/RangeSlider.md
An example of using RangeSlider to select a day range.
```xaml
```
--------------------------------
### Constructor
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/api-reference/Tile.md
Initializes a new instance of the Tile control.
```csharp
public Tile()
```
--------------------------------
### Font Awesome Icon Example
Source: https://github.com/mahapps/mahapps.metro/wiki/Icons
Example of using a Font Awesome icon from MahApps.Metro.IconPacks.
```xaml
```
--------------------------------
### LoginDialogSettings Example Usage
Source: https://github.com/mahapps/mahapps.metro/blob/develop/_autodocs/configuration.md
Shows an example of configuring and using LoginDialogSettings for a login prompt.
```csharp
var settings = new LoginDialogSettings
{
UsernameWatermark = "Enter your email",
PasswordWatermark = "Enter your password",
AffirmativeButtonText = "Sign In",
ShouldHideUsername = false,
ColorScheme = MetroDialogColorScheme.Theme
};
var loginData = await this.ShowLoginAsync(
"Authentication",
"Please sign in:",
settings);
if (loginData != null)
{
string username = loginData.Username;
string password = loginData.Password;
}
```
--------------------------------
### Change Window to MetroWindow
Source: https://github.com/mahapps/mahapps.metro/wiki/Quick-Start
Replaces the standard Window with MahApps.Metro's MetroWindow in the main window's XAML.
```XML
```