-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using AvaloniaExtensions; | ||
|
||
namespace ExampleApp; | ||
|
||
public class SettingsComponent : CanvasComponentBase { | ||
private ExampleSettings? _settings; | ||
private ExampleSettings Settings => _settings ??= GetSettings<ExampleSettings>(); | ||
|
||
private CheckBox _cbExampleToggle = null!; | ||
|
||
protected override void InitializeControls() { | ||
AddTextBlock("This is an imaginary settings component").TopLeftInPanel(); | ||
AddButton("Cancel", _ => SwitchToComponent<MainComponent>()).BottomRightInPanel(); | ||
AddButton("Ok", _ => SwitchToComponent<MainComponent>()).LeftOf(); | ||
AddTextBlock("This is a simple settings component").TopLeftInPanel(); | ||
_cbExampleToggle = AddCheckBox("Something to toggle").Below(); | ||
|
||
AddButton("Cancel", OnCancelClick).BottomRightInPanel(); | ||
AddButton("Ok", OnSaveClick).LeftOf(); | ||
} | ||
|
||
protected override void OnInitialized() { | ||
base.OnInitialized(); | ||
LoadSettings(); | ||
} | ||
|
||
private void OnSaveClick(RoutedEventArgs e) { | ||
Settings.ExampleToggle = _cbExampleToggle.IsChecked ?? false; | ||
SwitchToComponent<MainComponent>(); | ||
} | ||
|
||
private void OnCancelClick(RoutedEventArgs e) { | ||
LoadSettings(); | ||
SwitchToComponent<MainComponent>(); | ||
} | ||
|
||
private void LoadSettings() { | ||
_cbExampleToggle.IsChecked = Settings.ExampleToggle; | ||
} | ||
|
||
AddButton("Quit", _ => Quit()).BottomLeftInPanel(); | ||
public class ExampleSettings { | ||
public bool ExampleToggle { get; set; } | ||
} | ||
} |