I am programmatically creating a taskbar notify icon and Right Click ContextMenu in a C# WPF application.
A couple of the ContextMenu items have submenus whicr are populated from webservice calls. One of these is can span the entire height of the users screen, because it is over 100 entries, and you get the overflow arrows. I would like to be able to set max height to like 500.
I have been unable to figure out how to limit the size of these ContextMenu submenus programmatically. Below is the code I used to create the "Directory" submenu, which in theory can contain 0 to 1,000 entries.
Is it possible?
Any help is appreciated, Thank you.
m_menu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem newMenuItem4 = new System.Windows.Forms.MenuItem("Directory");
System.Windows.Forms.MenuItem newExistMenuItem4 = (System.Windows.Forms.MenuItem)this.m_menu.MenuItems[0];
if (numbers.Count > 0)
{
int indx = 0;
foreach (string number in getContactDirectory() )
{
newMenuItem4.MenuItems.Add(indx,
new System.Windows.Forms.MenuItem(number, new System.EventHandler(historyCall)));
indx++;
}
m_menu.MenuItems.Add(menuCounter, newMenuItem4);
menuCounter++;
}
You need to familiarize yourself with Control templates and XAML.
Have a look at the blog - http://xcalibur37.wordpress.com/2013/05/09/an-enhanced-menuitem-to-limit-submenu-height/
This should answer yoour question - Best way to set a MenuItem's sub-menu height?
Related
This is my code:
for (int i = 0; i < 30; i++)
{
FileListView.Items.Add(new ListViewItem(new[] { "asd1", "asd2" }));
if (i < 10)
{
FileListView.Items[i].Selected = true;
}
}
FileListView.ItemDrag += new ItemDragEventHandler(FileListView_ItemDrag);
but when I Run the application, I can't see the first 10 items selected. For see them, I need to click on one of them, and they will highlights (but of course deselected immediatly, since it is like click on a single row).
How can I preselect 10 items? So a user see them selected and then can click to drag/drop to some destination...
The items are being selected but the control is not activated. Use FileListView.Select() to activate the control.
It sounds like your ListView is not focused so when you select the items they won't highlight.
You can either focus the control before hand like this:
FileListView.Focus();
Or what's probably better is to disable the HideSelection property. This allows the ListView to display selected items when not focused.
FileListView.HideSelection = false;
Edit: With OPs new information that they need to show blue, give keyboard focus to the control once you're done:
FileListView.Select();
Did you set the multiselect property with the designer or by code ?
FileListView.MultiSelect=true ;
Try also:
FileListView.Invalidate() after the loop.
So, in a new form I create programmatically some labels and linklabels.
The number is NOT known by the start of the program. And I need to display them in a container or something, and when they are too many, the container should display a vertical scrollbar..
My Form is must have a fixed size
I tried Panel, LinkLabel but no success, meaning it doesn't show a scrollbar and some of the controls don't show up
Do you have any ideas?
(I want to make something like a table of contents, but which doesn't have a fixed number of items)
Thank you...
Some code:
for(int i=0; i<number ;i++)
{
Label l=new Label();
l.Name = i + ".label";
this.Controls.Add(l); // need to replace "this" with name of a control
l.Location(50, i * 20 + 50);
}
I solved this by using a Panel, and setting its AutoScroll property to TRUE. Now it works.
i am using .NET CF making application in window mobile.
need want to add textboc in third column of listview.
googled it but only getting solution for web application.
aint it possible in window mobile ????
code i tried so far... (although it is not working :-) )
for (int i = 0; i < soups.Length; i++)
{
ListViewItem li = new ListViewItem();
li.Text = "RSO" + (i+1);
li.SubItems.Add(arrval[i]);
//in 1st attemp i tried
li.SubItems.Add(new TextBox());
//in 2nd attemped
TextBox tbox = new TextBox();
li.SubItems.Add(tbox);
li.SubItems.Add(Convert.ToString(5 * (i + 1)));
li.SubItems.Add(Convert.ToString(35 * (i + 1)));
lst_option.Items.Add(li);
}
but both ways not working.... bcz of obvious reasons as i am trying to add obj in add() method instead of string :) :)
thnkx in advance
None of the out-of-the-box controls for the Compact Framework (ListView, ListBox, DataGrid, etc) provide this capability. The common work-around is to place a separate TextBox on the form and when a ListViewItem is selected, move the Textbox to cover the location of the subitem/cell, put the subitem/cell text into the TextBox, then make it visible.
I have a long ListView which contains a list of actions which my app is currently running (each action at a time).
Upon running each action, the relevant ListViewItem is bolded.
The ListView is long so I have vertical scroll bar.
My question is how to make the current running action shown to the user, meaning, how do I "scroll" the list view to that item.
I tried to manually select the row ==> didn't work.
I've used ListViewItem.EnsureVisible but that made the ListView flicker on each change.
Any idea? Thanks.
Edited: I've added some code, even though the code is pretty simple.
Whenever a new action is running, I run the following:
foreach (ListViewItem item in m_ListView.Items)
{
FontStyle style = ((index == value) ? FontStyle.Bold : FontStyle.Regular);
item.Font = new Font(item.Font, style);
if (index == value)
{
m_ModulesListView.EnsureVisible(index);
}
index++;
}
You means
listView1.EnsureVisible(listView1.Items.Count - 1);
Maybe you should call ListView.BeginUpdate() before your loop and ListView.EndUpdate() after your loop.
Found a nice solution.
It involves using win32 but it does the job.
Apparently, it is possible to set double buffering on the list which solves the flickering problem.
So, using EnsureVisible with the double buffering work just fine.
I'm using a panorama control in a WP7 app. One of the PanoramaItems takes you to another page, which then allows you send an email through the EmailComposeTask. If you don't select to send the email and press the back button, the Panorama returns to the item you last selected. However, if you do select to send an email (and therefore leave the app), it does not return to the previously selected PanoramaItem. Instead, it returns to the first item in the Panorama. I tried keeping track of the selected index and setting it, but I got an error saying the SelectedIndex is not settable. This is confirmed on MSDN documentation http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.panorama.selectedindex%28VS.92%29.aspx
Is there any way to manually set the selected index/item on a panorama? If not, is there a way for it to remember what was selected, even if the user leaves the app to compose an email?
I'm not sure if you can programmatically force an animation to another PanoramaItem, but you can change the Panorama.DefaultItem.
So you might have 3 PanoramaItem's and on the OnNavigatedTo() handler, change the default item via:
panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];
This should help when you recover from a tombstone.
You could try the solution posted by Silicon Shark in this thread. It's noted to work, but only on the initial display - which shouldn't be a problem for your requirements of restoring state after tombstoning.
How to programmatically set the visible item in a Panorama control?
You can get the currently active page from the panorama's SelectedIndex property.
Unfortunately setting DefualtItem is only an approximation to solving this problem, which you may have discovered already.
Edit: Be aware that setting DefaultItem, changes which page of the panorama is the first page. It's a subtle difference, but you will see how it matters looking at the positioning of the heading and the wrap around of the background image.
Here is a solution. It does work as expected and does not rearrange your panorama, so your user interface is consistent.
pan.SetValue(Panorama.SelectedItemProperty, panoramaItem);
Panorama temp = pan;
LayoutRoot.Children.Remove(pan);
LayoutRoot.Children.Add(temp);
LayoutRoot.UpdateLayout();
this is not a perfect solution in that it does not slide nicely like panorama should, and it is probably not very efficient, but on the other hand you are not changing the default item so your user interface stays consistent.
I tested solutions listed here without success. Here is what I did that works like a charm!
PanoramaItem panItem = (PanoramaItem)panorama.Items[1];
panorama.Items.Remove(panItem);
panorama.Items.Insert(0, panItem);
You need to remove the panel from the list and re-inserting it at the desired position!
Set new selected item by
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[newSelectedItem]);
However, it work only on the initial so my idea is let the panorama control re-init when we change the selected item. This is my code, just add this after Panorama.SelectedItem changing.
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]);
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;
But there is not transition effect now! Although, you can create your self.
It work great for me, this page also create a effect for sliding right http://xme.im/slide-or-change-panorama-selected-item-programatically
I'm using this model to change to a pivot when the device goes into landscape view, I'll probably end up extracting the current item to the application state. The panorama is a no-go in landscape orientation.
private int hub_page_index;
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
base.OnOrientationChanged(e);
if (panorama.Visibility == Visibility.Visible)
{
hub_page_index = panorama.SelectedIndex;
}
else if (pivot.Visibility == Visibility.Visible)
{
hub_page_index = pivot.SelectedIndex;
}
if (e.Orientation == PageOrientation.Landscape
|| e.Orientation == PageOrientation.LandscapeLeft
|| e.Orientation == PageOrientation.LandscapeRight)
{
// Display Pivot in Landscape orientation
pivot.SetValue(Pivot.SelectedItemProperty, pivot.Items[panorama.SelectedIndex]);
panorama.Visibility = Visibility.Collapsed;
pivot.Visibility = Visibility.Visible;
}
else
{
// Display Panorama in Portrait orientation
panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[pivot.SelectedIndex]);
pivot.Visibility = Visibility.Collapsed;
panorama.Visibility = Visibility.Visible;
}
}