I am working on a DM script that creates a technique which contains a few dialogs.
In this script I am trying to update the pulldown menu items in one dialog from inside another dialog.
I currently have a button inside the dialog with the pulldown menu called "update" which calls a function inside the dialog class that is called "updateDialog".
This function removes all pulldown menu items and then inserts all the items stored in a taglist.
It also changes the state of a few buttons in that dialog.
This update button works perfectly.
Now if I call this updateDialog function from inside the other dialog, the button states change as they should, but the pulldown menu does not update.
Does anyone know why this happens and/or if there is a way to make this work?
Thanks!
Example code:
taggroup menuitems = newtaglist()
object firstdialog, seconddialog
interface I_seconddialog{
void updatedropdowndialog(object self);
}
class firstdialog : uiframe{
void additemresponse (object self){
number items = menuitems.taggroupcounttags()+1
menuitems.taggroupinserttagasstring(infinity(), "Created item #"+items)
menuitems.taggroupopenbrowserwindow(0)
seconddialog.updatedropdowndialog()
}
taggroup createdialog (object self){
taggroup dialog, dialogitems, additembutton
dialog = DLGCreateDialog("first_dialog", dialogItems)
additembutton = DLGCreatePushButton("Add pulldown item", "additemresponse")
dialogitems.dlgaddelement(additembutton)
return dialog
}
object init (object self){
return self.super.init( self.createdialog() )
}
}
class seconddialog : uiframe{
number isbuttonenabled
void updatedropdowndialog (object self){
// Change the state of the state button to show that that does work
isbuttonenabled = abs(isbuttonenabled-1)
self.Setelementisenabled("statebutton",isbuttonenabled);
// Empty the dropdown as the menuitems list might be completely different
taggroup dropdown = self.lookupelement("dropdown")
taggroup dropdown_items
dropdown.taggroupgettagastaggroup("Items",dropdown_items)
dropdown_items.taggroupdeletealltags()
// Add the current tags in menuitems to the dropdown
for(number i=0;i<menuitems.taggroupcounttags();i++){
string item_name
menuitems.taggroupgetindexedtagasstring(i,item_name)
dropdown.dlgaddchoiceitementry(item_name)
}
}
taggroup createdialog (object self){
taggroup dialog, dialogitems, dropdown, updatebutton, statebutton
dialog = DLGCreateDialog("second_dialog", dialogItems)
taggroup initial_items
dropdown = DLGCreateChoice(initial_items,0,"dropdownchange").dlgidentifier("dropdown")
dropdown.dlgaddchoiceitementry("Initial item")
updatebutton = DLGCreatePushButton("Update dropdown", "updatedropdowndialog")
statebutton = DLGCreatePushButton("state changes", "stateresponse").dlgidentifier("statebutton")
dialogitems.dlgaddelement(dropdown)
dialogitems.dlgaddelement(updatebutton)
dialogitems.dlgaddelement(statebutton)
return dialog
}
object init (object self){
isbuttonenabled = 1
return self.super.init( self.createdialog() )
}
}
void main(){
String techniqueName = "Example"
Image techniqueIcon := RGBImage( "Test icon", 4, 75, 75 )
techniqueIcon = RGB( icol, irow, iradius )
object technique = CreateTechnique( techniqueName, techniqueIcon )
firstdialog = Alloc( firstdialog ).Init()
String taskName = "First dialog"
Number taskID = RegisterWorkflowTask( firstdialog, taskName )
Number bOpenByDefault = 1
Number bEssential = 0
AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )
seconddialog = Alloc( seconddialog ).Init()
taskName = "Second dialog"
taskID = RegisterWorkflowTask( seconddialog, taskName )
bOpenByDefault = 1
bEssential = 0
AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )
AddCustomTechnique( technique )
}
main()
Not an answer (yet), but a longer clarification comment
I'm testing your script code on GMS 3.4.2 and this is the behavior I see, running the script (once) right after GMS start:
Custom technique is added:
It shows two dialogs initially as:
Pressing "Update dropdown" on the Second dialog toggles the "state
changes" button enabled/disabled:
Pressing the "Add pulldown item" button on the First dialog each
time adds to the drop-down and toggles the "state changes" button in
the Second dialog (and displays the tagList of entries):
Isn't that exactly the intended behavior ?
Related
I have a program where I want the user to be able to register for an account. The main view controller has a register button that they can click. I want the window to be replaced, instead of sheet or modal segues. Then, when they click done, they will be redirected back to the main view controller.
You can use follow way to navigate to another window :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Click");
NSWindow newWindow = new NSWindow();
newWindow.Title = "Second Window";
newWindow.SetFrame(new CGRect(500, 500, 300, 200),true);
// set be key window and be front
newWindow.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
And when back to previous , also can use this way .
============================Update==================================
I will share an screenshot to explain that as follow :
You will see there are two WindowControllers and two ViewControllers .
First Window Controller (MainWindow) -> First View Controller (ViewController)
Second Window Controller (SecondWindow) -> Second View Controller (SecondViewController)
First View Controller :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Push");
var storyboard = NSStoryboard.FromName ("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier ("SecondWindow") as NSWindowController;
// display
controller.Window.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
Second View Controller :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Back");
var storyboard = NSStoryboard.FromName ("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier ("MainWindow") as NSWindowController;
// display
controller.Window.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
The effect :
==================================Update===============================
Open Main.storyboard with Xcode Interface Builder :
Review whether Storyboard ID be setted in project :
How do you use the radio button chanded method callback in dm script?
The following code is the example code provided by the documentation extended with two radio buttons. The resulting dialog is shown below.
Clicking the Button works perfectly fine. The Results tab shows "button callback". But when changing the Radio buttons nothing happens. After clicking OK I get an error which sais (as many times as I changed the radio buttons) that the given method does not exist.
How do I use the radio button callback?
class testDialog : UIFrame{
void buttonCallback(object self){
result("button callback\n");
}
void radioCallback(object self){
result("radio callback\n");
}
}
TagGroup dialog_items;
TagGroup dialog_tags = DLGCreateDialog("Test Dialog", dialog_items);
TagGroup button_tag = DLGCreatePushButton("Button", "buttonCallback");
dialog_items.DLGAddElement(button_tag);
TagGroup radio_list = DLGCreateRadioList(0, "radioCallback");
radio_list.DLGAddRadioItem("Radio 1", 0);
radio_list.DLGAddRadioItem("Radio 2", 1);
dialog_items.DLGAddElement(radio_list);
Object dialog = alloc(testDialog).init(dialog_tags);
dialog.Pose();
The callback for the radio button change method needs a TagGroup as second argument:
void radioButtonChanged(object self, TagGroup radio_list)
So changing the radioCallback() function in the code above to have those two parameters the example works fine (code provided below).
Note that this makes it easy to get the selected value of the radio buttons because the radio_list contains the value in the "Value" index:
void radioCallback(object self, TagGroup radio_list){
number value;
radio_list.TagGroupGetTagAsNumber("Value", value);
result("radio callback, radio list has value " + value + "\n");
}
The full working example of the code in the question is the following:
class testDialog : UIFrame{
void buttonCallback(object self){
result("button callback\n");
}
void radioCallback(object self, TagGroup radio_list){
result("radio callback\n");
}
}
TagGroup dialog_items;
TagGroup dialog_tags = DLGCreateDialog("Test Dialog", dialog_items);
TagGroup button_tag = DLGCreatePushButton("Button", "buttonCallback");
dialog_items.DLGAddElement(button_tag);
TagGroup radio_list = DLGCreateRadioList(0, "radioCallback");
radio_list.DLGAddRadioItem("Radio 1", 0);
radio_list.DLGAddRadioItem("Radio 2", 1);
dialog_items.DLGAddElement(radio_list);
Object dialog = alloc(testDialog).init(dialog_tags);
dialog.Pose();
private void PersonalInfoList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
System.Collections.IList list = e.AddedItems;
if (e.AddedItems.Count == 1)
{
IEnumerable<Category> categs = list.Cast<Category>();
Category em = categs.ElementAt<Category>(0);
int id = em.id;
int categoryid = em.categoryid;
string subcategoryname = em.subcategname;
NavigationService.Navigate(new Uri(String.Format("/SubCategories.xaml?id=" + id + "&categoryid=" + categoryid + "&subcategoryname=" + subcategoryname), UriKind.Relative));
}
}
if 2 items are there in list if click on first item then able to navigate to subcategories page.but again click on same first item not able to navigate.if click on 2 item after click on first item then able to navigate to subcategories page.....
You need to set the PersonalInfoList.SelectedIndex to -1 before or after your call to NavigationService.Navigate to reset the selected item.
If you are using a LongListSelector, set the SelectedItem to null
As Claus mentions in his answer, You need to set the PersonalInfoList.SelectedIndex to -1. However, if you are just rendering a list which is used for navigation, I created a NavigationList for this purpose:
A Fast Loading Windows Phone 7 NavigationList Control
This has the advantage of loading approximately twice as fast as a ListBox, also you do not have the same problem of having to 'reset' the selected-index.
What I want is that whenever I choose a certain index in my ComboBox a certain panel will become visible.
So Here is What I've done:
I've created a ComboBox
I've created 2 Panels
I've set the visibility of the 2 Panels in their properties tab to FALSE
However I was not able to set them to visible when somebody selects something on my ComboBox.
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox3.SelectedIndex == 0)
{
panel9.Visible();
}
}
Note: I've docked the 2 Panels in the same GroupBox.
What's wrong with my code T_T. It says non vocable member. :((
EDIT** I have a new problem. Everytime I pick another option. The panel which has been set to visible won't get back to hidden.
It will appear when I choose Index 1 but when I choose Index 2 it will also appear o.O?
It says non invocable member as you are calling visible, which is a property, as a method when you place the () after it. Just set the property to a value as below
panel9.Visible = true;
It should be panel9.Visible = true;
In that case just do something like this
if(index == 1)
{
panel9.Visible = true;
panel10.visible = false;
}
else
{
panel9.Visible = false;
panel10.Visible = true;
}
I'm trying to get the parent name of a context menu item.
So I tried something like this on menuItem_click :
Button clikance = (Button)sender;
string ladyGaga = Convert.ToString(clikance.Content);
But it didn't work (invalid cast exception). thx for any help
i have use a different approach for getting the sender button of my context menu. i have made an event on the "hold_click"
where i have get back the content of the button in a public string
private void GestureListener_DoubleTap(object sender, GestureEventArgs e)
{
Button clikance = (Button)sender;
ButtonEnvoyeur = Convert.ToString(clikance.Content);
}
If you look in the debugger at the point where the exception is raised, you'll see that sender isn't a Button, so trying to do an explicit cast to Button will obviously throw an InvalidCastException.
You can use the VisualTreeHelper to walk up the tree from your actual sender to the Button element:
VisualTreeHelper.GetParent((sender as DependencyObject));
UPDATE: In your instance sender is the MenuItem in the ContextMenu. You can get to the parent ContextMenu from the MenuItem by using the VisualTreeHelper, but unfortunately, ContextMenu does not expose any public members that enable you to access the owner; the Owner property is internal. You could get the source code for the Toolkit and expose the Owner property as publi instead, or use a completely different approach.
Have you thought of using an MVVM framework (such as MVVM Light) to wire up commands to these context menu items? Your current approach is very fragile and will break as soon as you change the visual tree. If you used commands, you could pass any additional information that you need for processing via the command parameter.
Use the Tag property of the MenuItem to retrieve your Button :
// Object creation
Button myButtonWithContextMenu = new Button();
ContextMenu contextMenu = new ContextMenu();
MenuItem aMenuItem = new MenuItem
{
Header = "some action",
Tag = myButtonWithContextMenu, // tag contains the button
};
// Events handler
aMenuItem.Click += new RoutedEventHandler(itemClick);
private void itemClick(object sender, RoutedEventArgs e)
{
// Sender is the MenuItem
MenuItem menuItem = sender as MenuItem;
// Retrieve button from tag
Button myButtonWithContextMenu = menuItem.Tag as Button;
(...)
}
Alex.