I am trying to create a menu bar with the following items: File, Database, Navigate, Window. However, I am getting an error which I do not understand: Could not resolve <mx:XMLList> to a component implementation. Can anyone explain the error to me? My code is as follows:
`
<mx:XMLList id="topLevelMenu">
<menuitem label="File" />
<menuitem label="Database"/>
<menuitem label="Navigate"/>
<menuitem label="Window" />
</mx:XMLList>
<mx:MenuBar width="100%" height="20" labelField="#label" id="mainMenuBar" dataProvider="{topLevelMenu}" />`
I googled for it and found a lot problems which generate this error message. None of them seemed to fit my case. When is this error generated?
The error means, basically, that the compiler can't find a component.
In this case, XMLList is not in the mx namespace. You didn't show the code where you import namespaces, but I assume you're using the default.
I suggest creating your XMLList in ActionScript, not MXML. I believe something like this should work:
public var topLevelMenu : XML = <menuItems>
<menuitem label="File" />
<menuitem label="Database"/>
<menuitem label="Navigate"/>
<menuitem label="Window" />
</menuItems>;
Then somewhere, perhaps in a creationComplete Handler you can change this into an XMLList
var myList : XMLList = topLevelMenu.menuitem
This code is written in the browser and untested.
Related
Can anyone post an example of how to setup fileuploaddialogbutton widget in a dialog?
I'm assuming this can be done - From the docs:
"The FileUploadDialogButton creates a button that opens a new dialog for uploading a file via the FileUploadField. Can be used inside edit dialogs where the upload must happen in a separate form in the new dialog."
The only results my searches seem to return is the Widget API documentation which offer no examples.
I've tried various random configurations in my dialog but get the JS error:
TypeError: c.setSize is not a function
c.setSize(cw || undefined, ch || undefined);
Note I'm not specifying any height or width in the config (documentation doesn't list them as options). Can anyone offer an example of how to configure this correctly (dialog.xml snippet would be great)?
Thanks in advance
EDIT:
Here is my dialog XML as it stands. It gives the error, but it's not the only version that causes this js error in the console, nor do I make any claims that this should work hence (due to the lack of documentation) me asking for an example.
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
height="{Long}700"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<tab1
jcr:primaryType="cq:Panel"
title="Tab 1">
<items jcr:primaryType="cq:WidgetCollection">
<name
jcr:primaryType="cq:Widget"
fieldLabel="Enter name"
name="./theName"
xtype="textfield"/>
<description
jcr:primaryType="cq:Widget"
fieldLabel="Change description"
name="./changeDescription"
xtype="richtext"/>
<files
jcr:primaryType="cq:Widget"
collapsed="{Boolean}false"
collapsible="{Boolean}false"
title="Files"
xtype="dialogfieldset">
<items jcr:primaryType="cq:WidgetCollection">
<test
jcr:primaryType="cq:Widget"
fieldLabel="Test"
xtype="textfield"/>
<file-upload
jcr:primaryType="cq:Widget"
dialogTitle="the dialog title"
fieldLabel="the field label"
text="the text"
xtype="fileuploaddialogbutton"/>
</items>
</files>
</items>
</tab1>
</items>
</items>
TreeView ContextMenu not fired events (ContextMenu Opened event not fire), I'm trying Caliburn.Micro.Telerik convention not solved problem.
TreeViewItemTemplate
<HierarchicalDataTemplate x:Key="TreeViewItemTemplate" ItemsSource="{Binding Types}"
ItemTemplateSelector="{StaticResource NamespaceItemTemplateSelector}">
<StackPanel Orientation="Horizontal">
<Path
Data=""
Height="11.458" Margin="0,0,5,0" RenderTransformOrigin="0.5,0.5" Stretch="Fill"
UseLayoutRounding="False" Width="11.264">
<Path.Fill>
<SolidColorBrush Color="#FF333333">
<SolidColorBrush.RelativeTransform>
<MatrixTransform Matrix="Identity" />
</SolidColorBrush.RelativeTransform>
<SolidColorBrush.Transform>
<MatrixTransform Matrix="Identity" />
</SolidColorBrush.Transform>
</SolidColorBrush>
</Path.Fill>
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</Path.RenderTransform>
</Path>
<TextBlock Text="{Binding Header}" Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}">
<TextBlock.ContextMenu>
<ContextMenu cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource Self},Path=UIElement.Tag}" cal:Message.Attach="[Event Opened] = [Action Opened($dataContext)]" >
<MenuItem Header="NewChild" cal:Message.Attach="NewChild($datacontext)"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</StackPanel>
TreeView
<TreeView x:Name="TreeView" ItemTemplate="{StaticResource TreeViewItemTemplate}" ItemsSource="{Binding Source}"/>
Before i tell you what was the problem i want to point out that the version of the code you uploaded is a bit different than the one you posted in your question.
OK, The problem lies exactly in this section of the template:
<TextBlock Text="{Binding Header}" Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}">
<TextBlock.ContextMenu>
<ContextMenu cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource Self},Path=UIElement.Tag}" cal:Message.Attach="[Event Opened] = [Action Opened($dataContext)]" >
<MenuItem Header="NewChild" cal:Message.Attach="NewChild($datacontext)"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
To fix it you need to replace it with this modified version:
<TextBlock Text="{Binding Header}" Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}">
<TextBlock.ContextMenu>
<ContextMenu cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.Tag}" cal:Message.Attach="[Event Opened] = [Action ContextMenuOpened($source)]">
<MenuItem Header="New" cal:Message.Attach="[Event Click] = [Action ClickMenuItem($source)]"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
The problem was caused by three issues:
In the template and specifically in this line of code <ContextMenu cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource Self},Path=UIElement.Tag}" the Path=UIElement.Tag was causing a binding error because there is no property on type ContextMenu that is called UIElement. Instead you have to replace that with the PlacementTarget property which represents the element in the user interface on which the context menu was opened.
The second issue is that you were putting the methods that handle those events on the wrong class. They shouldn't be on the ShellViewModel because in the template you are setting the Action.Target to be the DataContext behind the TextBlock which is actually the NamespaceViewModel in your situation, so the methods should go on the NamespaceViewModel.
The third and final issue is that your methods had the wrong signature so they couldn't be found by Caliburn.Micro. What i mean is that you are declaring your ContextMenuOpened method like this: void ContextMenuOpened(sender args, RoutedEventArgs args); but in the template you are calling the method like this: [Action ContextMenuOpened($source)] which sends the method the FrameworkElement that caused the event (ContextMenu in this case), so you should change the method signature for this event to this: void ContextMenuOpened(ContextMenu source) or the more general void ContextMenuOpened(FrameworkElement source).
Summary:
Fix your template to use the PlacementTarget property.
Move your methods to NamespaceViewModel.
Fix your methods signatures.
Finally: If you want to know everything about actions and action messages and what parameters get passed to what then you should really read the documentation wiki about Actions.
I have a dataProvider that's defined with mx:XML like this.
<mx:dataProvider>
<mx:XML format="e4x">
<root label="All Items">
<morning label="Evening" type="check" />
<evening label="Evening" type="check" />
<night label="Night" type="check" />
</root>
</mx:XML>
</mx:dataProvider>
This doesn't seem to be a valid option anymore with the new spark architecture. Can someone suggest how this can be done? I thought if I put in Declarations, it would work, but doesn't seem to be the case.
Try:
<fx:XML>
...
</fx:XML>
I have a MenuBar which contains general menu items like File, View, Tools ,Help.
I have sub items in each of those menuitems.
The problem is that i want to open the 'File' menu automatically when i press Alt+f key.
I could capture the keyevents on the view.
But how to open the File Menu of the MenuBar (what is the function that needs to be called from MenuBar Class to popup those sub menuitems) ?
I have searched for some information on google .. but cudnt find.
or else if u have any better solution or example ..plz do post it.
<root>
<menuitem label="File">
<menuitem label="New" enabled="false"/>
<menuitem label="Open.." enabled="false"/>
<menuitem label="Save" enabled="false"/>
<menuitem label="Restore" enabled="false"/>
<menuitem label="Print" enabled="true"/>
<menuitem type="seperator" enabled="false"/>
<menuitem label="Exit" enabled="true"/>
</menuitem>
<menuitem label="View" accesskey="v">
<menuitem label="Zoom In" enabled="true" maxValue="200"/>
<menuitem label="Zoom Out" enabled="true" maxValue="25"/>
</menuitem>
<menuitem label="Tools" enabled="false">
<menuitem label="item1" enabled="false"/>
<menuitem label="item2" enabled="false"/>
</menuitem>
</root>
Thanks in advance :)
Sriss
To open a menu at its position :
var fileMenu:Menu = mnuBar.getMenuAt(0);
pnt : Point = new Point(mnuBar.x,mnuBar.y + mnuBar.height);
pnt = localToGlobal(pnt);
fileMenu.show(pnt.x,pnt.y);
I solved it :)
var fileMenu:Menu = myMenuBar.getMenuAt(0);
fileMenu.show();
It works, but now the problem is .. the submenu is popping out at (0,0) location of the application not at the file Menu item ..!!!
It's a fake Menu!
A better way to do it is:
e.preventDefault(); // will play against pressed ESC, too
menuBar.setFocus();
menuBar.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, false, false, 0, Keyboard.RIGHT));
i need to fire separate method for individual menu item clicked ,so that individual item can handle separate method.
and i need know what all the properties are available in menu item like type="radio".
<mx:MenuBar id="jj" labelField="#label" itemClick="MenuItemClick(event)" x="23" y="228">
<mx:XMLList>
<menuitem label="File">
<menuitem label="New" type="radio"/>
<menuitem label="Open" data="Openfile" type="Check" />
<menuitem label="Save" />
<menuitem label="Exist"/>
</menuitem>
</mx:XMLList>
</mx:MenuBar>
Can you give any link or example for menubar control?
Thanks
Example from Adobe Flex docs MenuBar
Only three types allowed: check, radio, or separator.
<?xml version="1.0"?>
<!-- Simple example to demonstrate the MenuBar control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initCollections();" >
<mx:Script>
<![CDATA[
import mx.events.MenuEvent;
import mx.controls.Alert;
import mx.collections.*;
[Bindable]
public var menuBarCollection:XMLListCollection;
private var menubarXML:XMLList =
<>
<menuitem label="Menu1" data="top">
<menuitem label="MenuItem 1-A" data="1A"/>
<menuitem label="MenuItem 1-B" data="1B"/>
</menuitem>
<menuitem label="Menu2" data="top">
<menuitem label="MenuItem 2-A" type="check" data="2A"/>
<menuitem type="separator"/>
<menuitem label="MenuItem 2-B" >
<menuitem label="SubMenuItem 3-A" type="radio"
groupName="one" data="3A"/>
<menuitem label="SubMenuItem 3-B" type="radio"
groupName="one" data="3B"/>
</menuitem>
</menuitem>
</>;
// Event handler to initialize the MenuBar control.
private function initCollections():void {
menuBarCollection = new XMLListCollection(menubarXML);
}
// Event handler for the MenuBar control's itemClick event.
private function menuHandler(event:MenuEvent):void {
// Don't open the Alert for a menu bar item that
// opens a popup submenu.
if (event.item.#data != "top") {
Alert.show("Label: " + event.item.#label + "\n" +
"Data: " + event.item.#data, "Clicked menu item");
}
}
]]>
</mx:Script>
<mx:Panel title="MenuBar Control Example" height="75%" width="75%"
paddingTop="10" paddingLeft="10">
<mx:Label width="100%" color="blue"
text="Select a menu item."/>
<mx:MenuBar labelField="#label" itemClick="menuHandler(event);"
dataProvider="{menuBarCollection}" />
</mx:Panel>
</mx:Application>
Also bookmark this page Language Reference.
Vineth,
You are unable to add individual event handlers for menu items unless you dynamically create the menu bar and the sub items. This is more pain than it's worth, so I would recommend using the itemCLick handler as stated above and use a switch to determine what methods to fire. For example:
switch( event.item.#data ){
case "3A":
doSomething();
break;
case "3A":
doSomethingElse();
break;
defualt:
doDefault();
break;
}
Note: this is building off of zdmytriv answer