In LA, if need to save dialog position and other settings, use code from Cookbook topic "Dialog - save window placement, control values". Then add more code.
WPF ListBox does not have a Click event. This code uses event MouseDoubleClick. Double-click a listbox item to open a web page.
WPF ListBox does not have a Click event. This code uses event MouseDoubleClick. Double-click a listbox item to open a web page.
// script "The_Menu.cs"
using System.Windows;
using System.Windows.Controls;
using var sett = MySettings.Load();
var b = new wpfBuilder("The Menu").WinSize(400, 800);
b.Row(-1).Add(out ListBox lb);
b.R.Add("Label", out TextBox t, sett.text);
b.R.AddOkCancel();
b.End();
#if WPF_PREVIEW
b.Window.Preview();
#endif
b.WinSaved(sett.placement, o => {
sett.placement = o;
sett.text = t.Text;
});
lb.AddItem("-- Catagory 1 --");
lb.AddItem("QM Website", () => run.itSafe("https://www.quickmacros.com/"));
if (!b.ShowDialog()) return;
record class MySettings : JSettings {
public static readonly string File = folders.ThisAppDocuments + @"The_Menu.json";
public static MySettings Load() => Load<MySettings>(File);
public string placement;
public string text;
}
static class Ext {
public static ListBoxItem AddItem(this ListBox t, string text, Action doubleClicked = null) {
var li = new ListBoxItem { Content = text };
if (doubleClicked != null) li.MouseDoubleClick += (_, _) => doubleClicked();
else li.IsEnabled = false;
t.Items.Add(li);
return li;
}
}