Skip to content

Commit

Permalink
Added Dropdown change subscription example
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Jun 19, 2024
1 parent 17e468d commit b45b5cf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/MCMv5.Tests/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ protected override void OnBeforeInitialModuleScreenSetAsRoot()
"Three",
}, 2);
var proxyDropdown = new ProxyRef<Dropdown<string>>(() => proxyDropdownValue, o => proxyDropdownValue = o);

var changingString = new StorageRef<string>(string.Empty);
storageDropdownValue.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == "SelectedIndex")
{
if (sender is Dropdown<string> { SelectedIndex: 0 })
changingString.Value = "Selected Zero";
if (sender is Dropdown<string> { SelectedIndex: 1 })
changingString.Value = "Selected One";
if (sender is Dropdown<string> { SelectedIndex: 2 })
changingString.Value = "Selected Two ";
}
};

var builder = BaseSettingsBuilder.Create("Testing_Global_v5", "MCMv5 Testing Fluent Settings")!
.SetFormat("xml")
Expand Down Expand Up @@ -81,6 +95,7 @@ protected override void OnBeforeInitialModuleScreenSetAsRoot()
.AddDropdown("prop_8", "Test Proxy Ref", proxyDropdownValue.SelectedIndex, proxyDropdown, null)
.AddButton("prop_8_b", "Reset Proxy Ref", new StorageRef((Action) (() => proxyDropdownValue.SelectedIndex = 0)), "Reset Proxy Ref", null)
.AddText("prop_9", "Test", changingString, null)
)
.CreatePreset("test_v1", "Test", presetBuilder => presetBuilder
.SetPropertyValue("prop_1", true)
Expand Down

0 comments on commit b45b5cf

Please sign in to comment.