hi this is my xml i want to get only those menuitems which has type = "0". please help. AS you see there is menuitem in menuitem and in menuitem . i want to check all of them and if type is 0 i want to get that .
i want C# code
<Menu>
<menuitem alias="CB6CF9A26E92FB60487B538C57FDD0E9" slot="0" type="1" name="თანხის შეტანა">
<menuitem alias="5A8B27411D011CBE2EAB916A9E6E7B4C" slot="0" type="1" name="ბარათი">
<menuitem alias="B82505AC178863EFF64260EC52E410BE" slot="0" type="0" name="მარჯანიშვილის ფილიალი|VISA CLASSIC|GE****************0082|GEL" />
<menuitem alias="F0CF0D9A4D732C2026948FC34DFAC29F" slot="1" type="0" name="მარჯანიშვილის ფილიალი|VISA CLASSIC|GE****************0082|USD|კურსი - 2.49" />
<menuitem alias="6F6CA87FBACC28E8E5D09E29577B8E2A" slot="2" type="0" name="ცენტრალური ფილიალი|MC STANDARD|GE****************0006|GEL" />
<menuitem alias="329078EA8197E4F153B1B562EA07CD20" slot="3" type="0" name="ცენტრალური ფილიალი|MC STANDARD|GE****************0006|USD|კურსი - 2.49" />
</menuitem>
<menuitem alias="2BC77B16A194A82BF55AC48966CE6141" slot="1" type="1" name="შემნახველი">
<menuitem alias="7B0B015673196CC9FFB4D685B6448410" slot="0" type="0" name="მარჯანიშვილის ფილიალი|ჩემი სეიფი|GE****************0018|GEL" />
</menuitem>
<menuitem alias="1FC50E2144F4DF526D9ABCB45A078547" slot="2" type="1" name="ჩემი სეიფი - IBS(კოდი 3331)" />
</menuitem>
</Menu>
newDocument.SelectNodes("//Menu//menuitem[#type='0']")
this helped me .
Related
Instead of using Alt + F to open the menu "File", I want to change the holy key F1, how do I do that? Thanks!
<Grid>
<Menu Background="Transparent">
<MenuItem x:Name="asd" Header="_File">
<MenuItem x:Name="a" Header="1. _New" InputGestureText="ALT-N" Margin="0,18,0,0"/>
<MenuItem Header="2. _Open" InputGestureText="Alt+O"/>
<MenuItem Header="3. _Close"/>
<MenuItem Header="4. Save"/>
<Separator/>
<MenuItem Header="5. Delete" Margin="0,8,0,0"/>
<MenuItem Header="6. Rename"/>
<Separator/>
<MenuItem Header="7. Print" Margin="0,8,0,8"/>
<Separator/>
<MenuItem Header="8. Format Disk" Margin="0,8,0,8"/>
<Separator/>
<MenuItem Header="9. MINE(Decode)" Margin="0,8,0,8"/>
</MenuItem>
</Menu>
</Grid>
One way of getting the behaviour you desire would be to add an PreviewKeyDown event listener to your Grid or the parent.
<Grid PreviewKeyDown="Grid_PreviewKeyDown">
<Menu Background="Transparent">
<MenuItem x:Name="asd" Header="_File">
<MenuItem x:Name="a" Header="1. _New" InputGestureText="ALT-N" Margin="0,18,0,0"/>
<MenuItem Header="2. _Open" InputGestureText="Alt+O"/>
<MenuItem Header="3. _Close"/>
<MenuItem Header="4. Save"/>
<Separator/>
<MenuItem Header="5. Delete" Margin="0,8,0,0"/>
<MenuItem Header="6. Rename"/>
<Separator/>
<MenuItem Header="7. Print" Margin="0,8,0,8"/>
<Separator/>
<MenuItem Header="8. Format Disk" Margin="0,8,0,8"/>
<Separator/>
<MenuItem Header="9. MINE(Decode)" Margin="0,8,0,8"/>
</MenuItem>
</Menu>
</Grid>
Then in the underlying C# code add the following action event
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F1) // This filters what key was pressed
{
asd.IsSubmenuOpen = true; // This opens the menu
e.Handled = true; // Setting this to true prevents the any other events from occurring due to the key press
}
}
I am implementing a texteditor in WPF. I am pretty new to WPF and C#. I am able to get tooltip for "Cut","Copy","Paste" options. But how do I get tooltip for File operations like "New","Open","Save","Save_As" and "Close"? Also I do see that when I edit a file in my Richtextbox, the editor does not indicate that file is changed. How do I implement this feature? Any help is appreciated.
<MenuItem Header="_File">
<MenuItem Header="_New" Click="New_Click"/>
<Separator />
<MenuItem Header="_Open" Click="Open_Click"/>
<Separator />
<MenuItem Header="_Save" Click="Save_Click">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\FileSave.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Save As" Click="Save_As_Click">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\FileSaveAs.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="_Close" Click="Close_Click"/>
<Separator />
<MenuItem Header="_Exit" Click="Exit_Click"/>
</MenuItem>
<MenuItem Header="_Edit">
<MenuItem Header="_Cut" Command="ApplicationCommands.Cut" ToolTip="Cut">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\EditCut.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Copy" Command="ApplicationCommands.Copy" ToolTip="Copy">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\EditCopy.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Paste" Command="ApplicationCommands.Paste" ToolTip="Paste">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\EditPaste.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Undo" Command="ApplicationCommands.Undo" ToolTip="Undo">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\EditUndo.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Redo" Command="ApplicationCommands.Redo" ToolTip="Redo">
<MenuItem.Icon>
<Image Source="C:\Users\stambi\Documents\Visual Studio 2012\Projects\PatternEditor\PatternEditor\Images\EditRedo.png" Height="21"></Image>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
You do the same thing with New, Open, Save you have to define the ToolTip property.
Regarding how to determine if the file has changed depends on how you want to build it. Assuming you have Dock Windows as the parent of the RichTextBox Do you want an indicator that gives a * in the Header of the DockWindow or do you just want to know if the file has changed then you can use an event called TextChanged.
Inside this combobox I have a menu that contains multiple menus.
This is how it looks:
This is the XAML:
<ComboBox>
<Menu>
<MenuItem Header="Name">
<MenuItem Header="Last" />
<MenuItem Header="First" />
</MenuItem>
</Menu>
<Menu>
<MenuItem Header="Age">
<MenuItem Header="20" />
<MenuItem Header="24" />
</MenuItem>
</Menu>
</ComboBox>
When the user selects "Last"/"First"/"20"/"24" I want the combobox to set its selected item to one of this 4 items.
Is it possible? If yes, how can I do it?
Yes you can do that. But I am not sure if this is the best way cos I dont know your requirement in full.
XAML:
<ComboBox x:Name="cmb1" IsEditable="True" >
<Menu>
<MenuItem Header="Name" >
<MenuItem Click="MenuItem_Click" CommandParameter ="Last" Header="Last"/>
<MenuItem Click="MenuItem_Click" CommandParameter="First" Header="First" />
</MenuItem>
</Menu>
<Menu>
<MenuItem Header="Age">
<MenuItem Header="20" />
<MenuItem Header="24" />
</MenuItem>
</Menu>
</ComboBox>
vb Code:
Private Sub MenuItem_Click(sender As Object, e As RoutedEventArgs)
Me.cmb1.Text = CType(sender, MenuItem).CommandParameter.ToString()
End Sub
c# code :
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem menuItem = sender as MenuItem;
this.cmb1.Text = menuItem.CommandParameter.ToString();
}
I want to create a ComboBox that lets users select items the way the Windows XP start menu allows to select programs:
Is there a way to insert a cascaded ContextMenu inside a ComboBox?
I tried this but it doesn't work properly:
<ComboBox>
<MenuItem Header="Top Level 1">
<MenuItem Header="Sub Level" />
<MenuItem Header="Sub Level" />
</MenuItem>
<MenuItem Header="Top Level 2">
<MenuItem Header="Sub Level" />
<MenuItem Header="Sub Level" />
</MenuItem>
</ComboBox>
You will want to try somthing like this, The next level must be inside the first level.
<Menu Margin="0,0,0,283">
<MenuItem Header="Top Level 1">
<MenuItem Header="Sub Level" />
<MenuItem Header="Sub Level" />
<MenuItem Header="Top Level 2">
<MenuItem Header="Sub Level" />
<MenuItem Header="Sub Level" />
<MenuItem Header="Top Level 3">
<MenuItem Header="Sub Level" />
<MenuItem Header="Sub Level" />
</MenuItem>
</MenuItem>
</MenuItem>
</Menu>
Do you have to use a ComboBox?
Using the Menu control will make your MenuItems work easily... so I would use that instead: http://wpftutorial.net/Menus.html
You can always alter the look of it as well. There are some examples here: http://www.c-sharpcorner.com/uploadfile/mahesh/menus-in-wpf/
Else, did you try to wrap your menuitems in a simply?
I have an image that has a nested context menu defined in the XAML (shown below).
I am trying to use a for loop to find a menu and uncheck it using IsChecked=false.
my code is as follows:
for (int i = 1; i <= 16; i++)
{
MenuItem theMenu = (MenuItem)this.FindName("beat" + i.ToString());
theMenu.IsChecked = false;
}
the above does not work and returns a null.
what am I doing wrong!
excerpt from the XAML
<Image x:Name="Options" Height="35" Source="Images/pad-options-button.png" Stretch="Fill" Width="47" Canvas.Left="740" Canvas.Top="293"
MouseUp="Options_MouseUp">
<Image.ContextMenu>
<ContextMenu>
<MenuItem Header="Beats">
<MenuItem Name="beat1" Header="1" Click="MenuBeats_Click"/>
<MenuItem Name="beat2" Header="2" Click="MenuBeats_Click"/>
<MenuItem Name="beat3" Header="3" Click="MenuBeats_Click"/>
<MenuItem Name="beat4" Header="4" Click="MenuBeats_Click"/>
<MenuItem Name="beat5" Header="5" Click="MenuBeats_Click"/>
<MenuItem Name="beat6" Header="6" Click="MenuBeats_Click"/>
<MenuItem Name="beat7" Header="7" Click="MenuBeats_Click"/>
<MenuItem Name="beat8" Header="8" Click="MenuBeats_Click"/>/>
<MenuItem Name="beat9" Header="9" Click="MenuBeats_Click"/>
<MenuItem Name="beat10" Header="10" Click="MenuBeats_Click"/>
<MenuItem Name="beat11" Header="11" Click="MenuBeats_Click"/>
<MenuItem Name="beat12" Header="12" Click="MenuBeats_Click"/>
<MenuItem Name="beat13" Header="13" Click="MenuBeats_Click"/>
<MenuItem Name="beat14" Header="14" Click="MenuBeats_Click"/>
<MenuItem Name="beat15" Header="15" Click="MenuBeats_Click"/>
<MenuItem Name="beat16" Header="16" Click="MenuBeats_Click"/>
</MenuItem>
<MenuItem Header="Beat Type">
<MenuItem Name="Whole" Header="Whole" Click="MenuBeatType_Click"/>
<MenuItem Name ="Half" Header="Half" Click="MenuBeatType_Click"/>
<MenuItem Name ="Quarter" Header="Quarter" Click="MenuBeatType_Click"/>
<MenuItem Name ="Eighth" Header="Eighth" Click="MenuBeatType_Click"/>
<MenuItem Name ="Sixteenth" Header="Sixteenth" Click="MenuBeatType_Click"/>
</MenuItem>
</ContextMenu>
</Image.ContextMenu>
</Image>
</Canvas>
An other option is to get the context menu from the image.
var items = Options.ContextMenu.Items
foreach(MenuItem item in items)
{
// do your work with the item
}
Be arware that you will have to handle the sub items!
Items will have only 2 items in your case
You have incorrect markup. Last two symbols shouldn't be there:
<MenuItem Name="beat8" Header="8" Click="MenuBeats_Click"/>/>
However, you example perfectly works for me, but with accidental item:
"/>"
Just in the constructor of the class in code behind write NameScope.SetNameScope(contextMenu, NameScope.GetNameScope(this)); contextMenu is the name given to context menu of image. Actually ContextMenu is not the part of Visual tree so it cant find the names . but the above line of code will set context menu in the scope of visual tree and hence will find the names. Hope this will help.