Primary WinForms APIs:
.resx resourcesComponentResourceManagerProperties.Settings.DefaultPrimary Avalonia APIs/patterns:
ResourceDictionary, theme resourcesavares://... and app-relative assets)| WinForms | Avalonia |
|---|---|
designer-set localized strings in .resx |
bind text via localization service/view-model properties |
| embedded image resources | asset URIs and WindowIcon/Image sources |
| per-form resource managers | app-level resource dictionaries and typed localization abstractions |
| WinForms | Avalonia |
|---|---|
Properties.Settings.Default |
explicit settings service (for example JSON + DI/service locator) |
| automatic setting save on close | controlled persistence in lifetime shutdown path |
WinForms C#:
Text = Properties.Resources.MainWindowTitle;
iconPictureBox.Image = Properties.Resources.Logo;
if (Properties.Settings.Default.RememberFilter)
filterCheckBox.Checked = true;
Avalonia XAML:
<StackPanel xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:ShellViewModel"
Spacing="8">
<TextBlock Text="{CompiledBinding TitleText}" />
<Image Source="avares://MyApp/Assets/logo.png" Width="96" Height="96" />
<CheckBox Content="Remember filter"
IsChecked="{CompiledBinding RememberFilter, Mode=TwoWay}" />
</StackPanel>
public interface IAppSettings
{
bool RememberFilter { get; set; }
string PreferredCulture { get; set; }
void Save();
}
public sealed class ShellViewModel
{
private readonly IAppSettings _settings;
public ShellViewModel(IAppSettings settings, ILocalizationService localization)
{
_settings = settings;
TitleText = localization["MainWindowTitle"];
RememberFilter = _settings.RememberFilter;
}
public string TitleText { get; }
public bool RememberFilter { get; set; }
public void Persist()
{
_settings.RememberFilter = RememberFilter;
_settings.Save();
}
}