Issue with drop down menu selection

7 replies. Last post: December 22, 2011 1:29 AM by Yudi
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback

Hi, I have attached a sample project to demonstrate an issue I experienced with the drop down menu. Please run the application and try the following:

1. Click Button 1 to show a single item drop down menu.

2. Click Update 1 to dynamically add a second menu item to the drop down menu.

3. Click Button 1 and select the new (second) menu item. Important you actually select it.

4. Click on Update 2 to dynamically remove the second menu item.

5. Click on Button 1 and move the cursor over the remaining (first) menu item.

You will receive an exception. I believe the original selection of the deleted menu item is not being cleared when it is deleted and this is causing the subsequent attempt to interact with the menu to generate an exception.  Thanks, Jonathan

<Window x:Class="WpfApplication26.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <ItemsControl x:Name="MyToolBar" Grid.Row="0" />
  </Grid>
</Window>

 using System;

using System.Collections.Generic;
using System.Windows;
using Intersoft.Client.Framework;
using Intersoft.Client.UI.Aqua.UXRibbon;
namespace WpfApplication26 {
  public partial class MainWindow {
    public MainWindow() {
      InitializeComponent();
      MyToolBar.Items.Add(_dropDownButton1 = new UXRibbonDropDownButton { Content = "Button 1" });
      _dropDownButton1.DropDownOpened += DropDownButton1_OnDropDownOpened;
      MyToolBar.Items.Add(_updateButton1 = new UXRibbonButton { Content = "Update 1" });
      _updateButton1.Click += _updateButton1_OnClick;
      MyToolBar.Items.Add(_updateButton2 = new UXRibbonButton { Content = "Update 2" });
      _updateButton2.Click += _updateButton2_OnClick;
      for (var i = 0; i < 1; i++) { _myItems.Add(String.Format("Item {0}", i + 1)); }
    }
    private readonly UXRibbonDropDownButton _dropDownButton1;
    private readonly UXRibbonButton _updateButton1;
    private readonly UXRibbonButton _updateButton2;
    private readonly List<String> _myItems = new List<String>();
    private void DropDownButton1_OnDropDownOpened(Object sender, ISRoutedEventArgs eventArgs) {
      // REQUIRED TO SUPPRESS EXCEPTION
      //if (_dropDownButton1.Items.Count > 0) ((UXRibbonMenuItem)_dropDownButton1.Items[0]).IsSelected = true;
      _dropDownButton1.SelectedIndex = -1;
      // REQUIRED TO SUPPRESS EXCEPTION
      _dropDownButton1.Items.Clear();
      foreach (var myItem in _myItems) { _dropDownButton1.Items.Add(new UXRibbonMenuItem { Header = myItem }); }
    }
    private void _updateButton1_OnClick(Object sender, RoutedEventArgs eventArgs) {
      _myItems.Remove("New Item");
      _myItems.Insert(0, "New Item");
    }
    private void _updateButton2_OnClick(Object sender, RoutedEventArgs eventArgs) {
      _myItems.Remove("Item 1");
    }
  }
}

 

All times are GMT -5. The time now is 6:36 PM.
Previous Next