When I expand a TreeView node by clicking on the plus sign right to it, the node gets selected. How can I avoid this? I want to be able to expand nodes without changing the selected node (like in RegEdit.exe, for example), and only change selection when the node text is clicked .
(Forgive me for what seems to be a basic question - I did search around, but found nothing. Any pointers or links are welcome.)
I believe there is a BeforeSelect event you can tap into, which should allow you to cancel node selection if the selected node has children.
private void MyTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
If (nodeWithChildren) e.Cancel = True
}
A bit late to the party with this.
You can use a Hit Test.
private void myTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeViewHitTestInfo info = myTreeView.HitTest(e.Location);
if (info.Location == TreeViewHitTestLocations.Label)
{
TreeNode node = myTreeView.GetNodeAt(e.Location);
//do something
}
}
This will only select the node if the label is clicked.
Hope this helps.
Related
We have a tool that is being integrated into our application. We have some strict borders around us too in that we cannot modify the application except for our extensions. I have searched here, I've searched the internet, but cannot find any postings about this problem.
I have a Windows Form that contains a ListView and our user requires we create a checkbox to Select/Deselect all. I have the event handler for when the check box state changes and call the routine to set everything to Selected.
private void SelectAllEventHandler(object sender, EventArgs e)
{
ChangeState(RadCapListView, SelectAllRadcap.Checked);
}
private void ChangeState(SWF.ListView control, bool state)
{
if (control.CheckBoxes)
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Checked = state);
}
else
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Selected = state);
}
control.Refresh();
}
Going into debug mode all items are marked as selected.
Also at the control level SelectedItems is properly updated.
The issue is that visually the control just will not highlight the selected items like we have our WPF forms doing. As you can see in the code I also tried to refresh the control hoping that would show items selected, but no joy.
Has anyone solved this problem in getting selected items to display properly?
Thank!
Instead of using control.Refresh(), try control.Focus().
I'm using FlipView to show some items in a page. The webservice I'm getting the data from support paging, so I'm adding the next page of items to the FlipView when the user has scrolled to the current last item e.g. if the page size is 5, I'm adding 5 more items whenever the SelectedIndex of FlipView is 4,9,14,19 etc. (index starts at 0).
FlipView has two tiny arrows that we can use in desktop environment (using Mouse) to navigate through the FlipView. When we are at the last item, the right arrow would disappear, because we cannot go any further. Now, if I add more items to the list at this point, the right arrow doesn't reappear, so it doesn't give the impression that there are more items in FlipView. The right arrow would only reappear if
We hover mouse on the left arrow
We click at the location where the right arrow should be
Which isn't a good solution and it requires further user education. Is there any way to address this issue?
Here is a git repo that shows the issue: https://github.com/4bh1sh3k/FlipViewDemo. To repro the issue, scroll till the last item, and then use the button below to add more items to the FlipView.
This should be determined by the control itself. If you do want the button displayed automatically, you may force the next button (which named NextButtonHorizontal in FlipView style and template) to visible after more items added. For how to get the NextButtonHorizontal button you could use VisualTreeHelper class. For example:
private void OnButtonClick(object sender, RoutedEventArgs e)
{
AddImageUris();
IEnumerable<Button> items = FindVisualChildren<Button>(myFlipView);
foreach (Button item in items)
{
if (item.Name == "NextButtonHorizontal")
{
item.Visibility = Visibility;
}
}
}
private static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
By the way, this can resolve your issue but I'm not very recommend that. Avoid using a flip view control for larger collections, for large collections, consider a ListView or GridView. More details please reference FlipView guidelines.
I am using UltraDropDown control to bind a column of one UltraGrid control to list People category in list format.
This drop-down control have more than 25 items and show 8 categories Max, it's very fine. Now whenever I click on drop-down control to see all people category list then i have to hold scroll bar and drag down to see all categories. but I want to show all categories when I mouse scroll and its automatically move up and down to show all, and one more thing I want, when i mouse hover on listed categories then hover item should be shaded or colored.
Please help on both topic.
Thanks & Regards,
Shashi Bhushan Jaiswal
I believe that the first requirement is by default as behavior. Are you handling the MouseWheel event for this to not work?
Here is the code for your second requirement but I do not know if it is a good approach to use the MouseHover event as you like but this is your requirement:
void ultraDropDown1_MouseHover(object sender, EventArgs e)
{
if (cell != null && isInItem) {cell.Cell.Appearance.BackColor = Color.Red;}
}
CellUIElement cell;
bool isInItem = false;
private void ultraDropDown1_MouseEnterElement(object sender, Infragistics.Win.UIElementEventArgs e)
{
if (e.Element is EditorWithTextDisplayTextUIElement && e.Element.Parent.Parent is CellUIElement)
{
cell = (CellUIElement)e.Element.Parent.Parent;
isInItem = true;
}
else isInItem = false;
}
currently I'm developing an app for WP7 but came across a little problem with a Listbox event call Selection_Change. The problem is that when i return to the page that contains the listbox the selection_change event triggers without being changed at all or without any user input. The listbox code is similar to this:
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
}
On the page I navigate to, the only way out of the navigated page is by pressing back button or start button meaning that it will return to the page that contains the listbox. When I Navigate back the selection change triggers leading me sometimes to a exception. Has anyone been through this before?
Consider always checking if it's -1 (the default value).
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
if (index != -1)
{
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
lsbHistory.SelectedIndex = -1; // Set it to -1, to enable re-selection.
}
}
Also, you should consider wrapping the Navigate call in Dispatcher.BeginInvoke to have a better, more smooth, page transition.
The event will be fired when the list is populated.
The simplest solution for you will probably be to add a check that there is nothing selected before triggering your navigation:
if (lsbHistory.SelectedIndex > -1)
{
// do navigation
}
One thing to notice is that when you navigate back to the page which containt the ListBox, the ListBox still has the SelectedItem set to the value it had when the user navigated away. This means that lsbHistory.SelectedIndex will get the index of the item which was selected when the user navigated forward.
Maybe there's something in your code which presumes that the ListBox's SelectedItem is null when the user navigates to the page?
I'm designing a reading app with pivot control. When coming from the first page, I want to disable the right-flick event so that the user can just flick left to get to the next page. When coming from the last page, I want to disable the left-flick event.
There is a lockablePivot control in Silverlight Toolkit, but this control will disable all the flick event. Would anybody give me some suggestions.
Have you looked at the LockablePivot Control in microsoft silverlight toolkit?
http://www.windowsphonegeek.com/articles/Windows-Phone-Toolkit-LockablePivot-in-depth
I think you should rethink your design decision here. Metro design language states how pivots work and people are used to this. Changing this will make the user experience worse for people because they expect you to be able to flick round in the pivot.
Using a PivotItem like this goes against the UI Guide and shouldn't really be implemented. However, for the sake of theory if nothing else, you could do something like this.
Give your first and last PivotItem a name.
<controls:PivotItem Header="Item1" Name="first">
...
<controls:PivotItem Header="Item5" Name="last">
Handle the Pivot's LoadingPivotItem and LoadedPivotItem events. You can then do something like this:
//class level variable we use for the current pivot
PivotItem currentItem = null;
private void Pivot_LoadingPivotItem(object sender, PivotItemEventArgs e)
{
//if the next item is going to be "first" pivot
//and the previous item was the "last" pivot...
if (e.Item == first && currentItem == last)
{
//...reset the Pivot back to the last one.
mainPivot.SelectedItem = last;
}
//same theory as above but checking if we're
//sliding to the last one from the first one
if (e.Item == last && currentItem == first)
{
mainPivot.SelectedItem = first;
}
}
private void mainPivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
//once the pivot is loaded, update the currentItem
currentItem = e.Item;
}