1
Vote

Collapsed DropDownBox displays first item instead of blank when there is no selection

description

By showing the first item instead of blank (and yes, I am aware that the selected index is set to first when items source changes but I explicitely set it to -1 after that), the user naturally won't change the selection if satisfied with what's shown. But in reality there is nothing selected which may lead to application bugs or frustrating UX.
 
Fix:
 

Index: C:/Work/Learn/Silvermoon/SilvermoonSvn/Silvermoon/Silvermoon/Controls/ListView/DropDownBox.cs

--- C:/Work/Learn/Silvermoon/SilvermoonSvn/Silvermoon/Silvermoon/Controls/ListView/DropDownBox.cs (revision 52428)
+++ C:/Work/Learn/Silvermoon/SilvermoonSvn/Silvermoon/Silvermoon/Controls/ListView/DropDownBox.cs (working copy)
@@ -310,6 +310,7 @@
     private bool IsItemVisible(Rectangle rect)
     {
  • if (!IsExpanded && SelectedItemIndex == -1) return false;
         if (rect.Bottom < 0) return false;
         return rect.Top < Height;
     }
    @@ -357,6 +358,12 @@
         }
     }
    
  • protected internal override void OnTap(TapEventArgs e)
  • {
  • base.OnTap(e);
  • if (!e.Handled && !IsExpanded && SelectedItemIndex == -1 && Count > 0) IsExpanded = true;
  • }
    +
     public void BringItemIntoView(int itemIndex, bool animated)
     {
         if (selectedIndex != itemIndex) IsExpanded = true;

comments