.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Adding a Command in a Dynamic MenuItem

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :WPF
Hello, and thank you for taking a look at this question.

I am developing my own Most Recent Used sub-menu. I have developed my main File Menu items (Open, Close, Save etc) in my XAML and included a binding for these to my commands which are defined in my ViewModel. These all work fine.

I have decided to save the file path and date into an XML file for simplicity. I can read this in and in my ViewModel I have a ListCollectionView property which exposes the XML elements. Still fine!

In my XAML I can bind my Recent Items sub-menu to the Filename item in my ListCollectionView without a problem, but I cannot seem to figure out how to bind each sub-menu item to a Command which will determine which file to open.

My XAML so far is as follows:

            x:Name="MainMenu" Background="#FFFFFFFF" BorderBrush="#FF000000" Margin="0,0,0,2.723" Grid.ColumnSpan="2" d:LayoutOverrides="Height, GridBox">
            <MenuItem Header="_File">
                <MenuItem Header="_Open" InputGestureText="Ctrl+O" Command="{Binding Path=OpenCommand}"/>
                <MenuItem Header="_New" InputGestureText="Ctrl+N" Command="{Binding Path=NewCommand}"/>
                <MenuItem Header="_Close" InputGestureText="Ctrl+Q" Command="{Binding Path=CloseCommand}"/>
                <MenuItem Heade

View Complete Post

More Related Resource Links

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Adding Dynamic Rows in GridView with TextBoxes

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

Adding Dynamic Rows in GridView with TextBoxex in C#

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

Dynamic Checkboxlist exception when adding to Panel when using Master Page


In essence, I am creating Dynamic Checkboxlist controls and adding them to a Panel.  It works well when I do not have a Master Page configure to this webpage. Once I have a masterpage congifured.. I get a "Object Reference not set to instance of object" error on the Panel_Control.Controls.Add(Checkboxlistnew) line:

protected void Page_PreInit(object sender, EventArgs e)
        XML OXML = new XML();
        alistChkBoxLabels = OXML.XMLTransform("C:\\Documents and Settings\..\\Config_new.xml", "config_options/check_box/applications/app/@name");
        int count = 1;
        alistCheckisFacility = new ArrayList();
        alIDTracker = new ArrayList();
        while (count <= alistChkBoxLabels.Count)

            Checkboxlistnew = new CheckBoxList();
            Checkboxlistnew.ID = count.ToString();
            Checkboxlistnew.Items.Add(new ListItem(alistChkBoxLabels[count - 1].ToString(), alistChkBoxLabels[count - 1].ToString()));

            String sAppName = alistChkBoxLabels[count - 1].ToString().Trim();

            alistCheckisFacility = OXML.XMLTransform("C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\WebSites\\User_Trial\\Config_new

Adding source redirect code to end of a URL which used a dynamic data value

I'm trying to add some source redirect code to the end of a URL in a Data Form Web Part on a simple SharePoint aspx page. This is the basic url: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID} However I want to add a source redirect to the end of the URL so that it returns to a particular page rather than the list's default page. I have tried all of the following: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}&source=/itservices/Pages/MyOverview.aspx That causes an error in the web part stating "This Web Part does not have a valid XSLT stylesheet: Error; A semi colon character was expected". I tried replacing the ampersand with the URL encoded character: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}%26source=/itservices/Pages/MyOverview.aspx But when opening from this URL the form contains no data. What am I missing or can this not be done? Thanks.  

What's the difference between a dynamic data project and adding a gridview to a "normal" project?

Hi,I'm having difficulty understanding what dynamic data actually is.There is an option to specifically create a dynamic data project, but I don't understand the difference between this, and just adding some kind of data control, like a gridview or detailsview for example.If someone can help me understand this better I'd really appreciate it.

MenuItem using Command is disabled for no reason


I have a Window (acting as an MDI) with a menu containing many Items which are linked to commands. When I start my application all menu items are enabled. When i click on one which opens a custom modal dialog, and then go back to the menu, ALL menu items that have commands are disabled :(

Ive read around and I think the problem is something to do with FocusScope and FocusManager.

When I open another window and click in a textbox then go back to the menu, the menu items are enabled.
Ive tried seeting FocusManager.IsFocusScope = True within the menu which didnt make any difference.

Any help would be appreciated as Ive spent a while on this and got nowhere. 


Gridview - Update with Dynamic SELECT Command?


Hi All...

We created a GridView-based webform with Update using the design wizards - very nice and it works great.  But then we wanted to the ability to create the SELECT command dynamically based on other controls on the page.  We added something like the following to Page_Load()...

            SqlDataSource1.SelectCommand = "SELECT [StationId], [IP] FROM [Stations]";

The GridView populates normally, but the Update no longer works.  It changes the "Edit" link to "Update", gives the user the edit boxes, but when "Update" is clicked it never seems to write the new data to the database.  No error - it just doesnt work...

Any thoughts?  How can we change the SELECT command (and Connection String) dymamically and still retain the Update functionality?

Many thanks - Curt.  Code follows...

    protected void Page_Load(object sender, EventArgs e)
        //  Doesn't work with or without this conditional
        //if (!IsCallback)
            SqlDataSource1.SelectCommand = "SELECT [StationId], [IP] FROM [Stations]";

adding dynamic script


    <asp:Panel ID="Panel7" runat="server">
        <div id="Div4" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" />
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

code behind:

        protected void Page_Load(object sender, EventArgs e)
            if (CheckBox1.Checked)
                String csName = "CounterScript";
                Type csTyp

Invoking Command In WPF SUb MenuItem


                              <MenuItem Header="Flag(s)" ItemsSource="{Binding Path=LineItemFlags}" Command="{Binding AssignFollowupCommand}" 
                                  CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, 
                                    AncestorType={x:Type ContextMenu}}, Path=PlacementTarget}">
                            <MenuItem.ItemContainerStyle >
                                <Style TargetType="{x:Type MenuItem}">
                                    <Setter Prop

Syntax error adding a parameter to xp_cmdshell command



I am trying to add a parameter to a bcp query that will be run in xp_cmdshell but am getting a syntax error at the '+' character.  Been staring at it for two hours and have concluded that  some outside help is needed. 

The command is:

EXEC xp_cmdshell 'bcp "SELECT * FROM [CensusData].[dbo].[Main] where zBarCode = ' + @zBarCode + '"  queryout "C:\temp_housing_data.txt" -T -c -t -S "MyServerName"'

The syntax is on the first '+' character and it simply says "Incorrect syntax near '+'"

Please help.

Dynamic Sub Menu Item Command Not working in WPF...MVVM

<MenuItem Header="Flag(s)" ItemsSource="{Binding Path=LineItemFlags}" >
                                <Style TargetType="{x:Type MenuItem}">

Problems with Binding Icon in dynamic MenuItem


I'm don't understand when I use hardcoded
<MenuItem.Icon><Image Source="images\image.png"/></MenuItem.Icon>
all works fine, but when I use binding it doesn't work :( !!!

<XmlDataProvider x:Key="data">
Items xmlns=""

Adding dynamic watermark to SharePoint 2010 document when open? (on browser view)


hi all,

In Sharepoint 2010, how to adding dynamic watermark to word 2010 when opening?

I thinking,

may be just need configure in sharepoint 2010?

or need sharepoint develop?


What you guys think? Any thoughts are welcome!

Thank you!


Adding multiple attachment (files) to a dynamic variable so it can be send to a email. VB 2010


Hello !

I need some advice on what to use for adding multiple attachment to a email. I'm using VB 2010.

First, I have a Form in my company web site to fill a reclamation ..... when you fill and send it, it convert the form into a PDF, save it in the client side "TEMP" and finally get the PDF and send it to a email..... that's perfectly  fine. I add to the form the capability of attach multiple files with file upload to the same "TEMP" and displayed in a Grid View to remove or add files and send everything to a email, the attachment capability is working. Everything is working with the PDF not the files(attachments). 

There is a way to get the multiple files from the "TEMP" folder and add it to some dynamically variable (array list, attachment collection, list collection, etc.) so all can be send to the email. I already know the way to put it into the email with the PDF. The problem is to get the files and add it to the dynamic variable and that it work with the email.

If the code is need it, let me know.


Copying rows using a dynamic SQL Command variable


I have a table with the Source TableName and Source ColumnName. I am trying to use SSIS to extract data from my source based on the tables and columns. I am using a Script Task to dynamically create the SELECT statement, no problems with that.

Next, I have a data flow task with a Source OLE DB Connection and the Data Access mode is using this dynamically created select statement. I am however unable to use this because this SELECT statement variable is not populated until runtime.

Basically I want to COPY ALL ROWS from the source to a destination. 

Is this possible? What is wrong with my assumptions? Any suggestions?


You are so wise...like a miniature budha covered in fur. -Anchorman

Adding Dynamic Maps to Contact Forms with REST Web Services in InfoPath 2010

Learn to use the REST Web service data connection feature in InfoPath 2010 to add a dynamic map to a list form for contacts in SharePoint Server 2010.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend