Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM to AL Help
#2
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.

Code:
Copy      Help
// 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;
    }
}


Messages In This Thread
QM to AL Help - by ScottF - 06-07-2024, 01:57 PM
RE: QM to AL Help - by Gintaras - 06-07-2024, 05:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)