I have a sample "multi-tab" wpf window I'm trying to build. I'd like to add buttons that *don't* result in the window being closed. I've added an Action handler, but I'm having trouble accessing the rest of the form data from the wpf window in that action. I'm a bit stuck. In the below code, I'd really like to access "generic_t1.Text" in the method printIt(WBButtonClickArgs).
I can find the form element using a w/elm find but that seems a bit hack-ish to me?
Alternatively I think I discovered that if a button is inside a page and it has a button Id associated (it should set ResultButton) I don't get a return value for the buttons inside the page. Only in the outside wpfBuilder.
Again, my preference would be to use the Action approach and figure out a way to access the text boxes, combo boxes etc that are in the wpf page.
Sample code below:
ok. .... after scratching my head on this.. I think I came up with a way. Similar to the way I'd handle "global" variables in csharp. Not sure this is the "right way", but it should work. Comments on this approach:
I can find the form element using a w/elm find but that seems a bit hack-ish to me?
Alternatively I think I discovered that if a button is inside a page and it has a button Id associated (it should set ResultButton) I don't get a return value for the buttons inside the page. Only in the outside wpfBuilder.
Again, my preference would be to use the Action approach and figure out a way to access the text boxes, combo boxes etc that are in the wpf page.
Sample code below:
C# code:
// script ""
using System.Windows;
using System.Windows.Controls;
script.setup(trayIcon: true, lockExit: true);
Action<WBButtonClickArgs> doAction = printIt;
var b = new wpfBuilder("Signal Magic").WinSize(400)
.Row(-1).Add(out TabControl tc).Height(400)
.End();
wpfBuilder _Page(string name, WBPanelType panelType = WBPanelType.Grid) {
var tp = new TabItem { Header = name };
tc.Items.Add(tp);
return new wpfBuilder(tp, panelType);
}
_Page("Page One")
.R.Add(out TextBlock generic_instructions)
.R.Add(out Separator _)
.R.Add("How Many", out TextBox generic_t1)
.R.AddButton("go", doAction)
.R.AddButton("stop", 22)
.End();
generic_instructions.Text = "This will do some stuff";
generic_instructions.TextWrapping = TextWrapping.Wrap;
_Page("Page Two")
.R.Add("Combo", out ComboBox _).Editable().Items("One|Two|Three")
.R.Add(out CheckBox _, "Check")
.End();
_Page("Page Three")
.R.Add("Combo", out ComboBox _).Editable().Items("One|Two|Three")
.R.Add(out CheckBox _, "Check")
.End();
_Page("Page Four")
.R.Add("Combo", out ComboBox _).Editable().Items("One|Two|Three")
.R.Add(out CheckBox _, "Check")
.End();
_Page("Page Five")
.R.Add("Combo", out ComboBox _).Editable().Items("One|Two|Three")
.R.Add(out CheckBox _, "Check")
.End();
_Page("Page Six")
.R.Add("Combo", out ComboBox _).Editable().Items("One|Two|Three")
.R.Add(out CheckBox _, "Check")
.End();
b.End();
b.ShowDialog();
// I could do a switch statement based on which button was selected,
// but it seems that the resultButton for the overall form isn't cascaded
// from inside a tab page? I get zero every time I run this and click on the "stop" button
print.it(b.ResultButton);
void printIt(WBButtonClickArgs args) {
var w = wnd.find(1, "Signal Magic", "HwndWrapper[Script1;*");
var e = w.Elm["TEXT", "How Many"].Find(1);
print.it(e.Value);
}
ok. .... after scratching my head on this.. I think I came up with a way. Similar to the way I'd handle "global" variables in csharp. Not sure this is the "right way", but it should work. Comments on this approach:
C# code:
// script ""
using System.Windows.Controls;
Action<WBButtonClickArgs> doGoButton = printIt;
var b = new wpfBuilder("Window").WinSize(400);
b.Row(-1).Add(out TabControl tc).Height(300..);
var bMain=b;
wpfBuilder _Page(string name, WBPanelType panelType = WBPanelType.Grid) {
var tp = new TabItem { Header = name };
tc.Items.Add(tp);
return new wpfBuilder(tp, panelType);
}
//--------------------------------
b = _Page("Page1");
b.R.Add("Text", out values.count);
b.R.AddButton("GO!", doGoButton);
b.End();
//--------------------------------
b = _Page("Page2");
b.R.Add("Combo", out ComboBox _).Editable().Items("Zero|One|Two");
b.R.Add(out CheckBox _, "Check");
b.End();
//--------------------------------
//tc.SelectedIndex = 1;
b = bMain.End();
if (!b.ShowDialog()) return;
print.it(b.ResultButton);
void printIt(WBButtonClickArgs args) {
print.it(values.count.Text);
}
static class values {
public static TextBox count;
}