Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Problem with WPF Combobox

Problem with WPF Combobox

Scheduled Pinned Locked Moved WPF
csharpwpfhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    babongita
    wrote on last edited by
    #1

    I have a combobox where the ItemsSource is bound to a ObservableCollection and the SelectedItem is bound to a string DependencyProperty. The ObservableCollection is populated so that the first string is an string.empty, so that something by default is not selected. My problem is this, if I select something in the combobox beside the string.empty (by clicking the drop down arrow and left clicking on an item, you can click the drop down arrow and select the string.empty item. However you can use the scroll on the mouse and select the string.empty. Then the caveat is that you can not scroll with the mouse to something that is not string.empty, you have to hit the drop down arrow and select an item with a left mouse click. Any ideas, this has me stumped.

    M P 2 Replies Last reply
    0
    • B babongita

      I have a combobox where the ItemsSource is bound to a ObservableCollection and the SelectedItem is bound to a string DependencyProperty. The ObservableCollection is populated so that the first string is an string.empty, so that something by default is not selected. My problem is this, if I select something in the combobox beside the string.empty (by clicking the drop down arrow and left clicking on an item, you can click the drop down arrow and select the string.empty item. However you can use the scroll on the mouse and select the string.empty. Then the caveat is that you can not scroll with the mouse to something that is not string.empty, you have to hit the drop down arrow and select an item with a left mouse click. Any ideas, this has me stumped.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      babongita wrote:

      the SelectedItem is bound to a string DependencyProperty.

      What does this binding look like? I can't reproduce the problem if this binding is left out. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      B 1 Reply Last reply
      0
      • M Mark Salsbery

        babongita wrote:

        the SelectedItem is bound to a string DependencyProperty.

        What does this binding look like? I can't reproduce the problem if this binding is left out. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        B Offline
        B Offline
        babongita
        wrote on last edited by
        #3

        <ComboBox x:Name="cboDistrict" IsSynchronizedWithCurrentItem="True" Grid.Column="1" Grid.Row="0" Style="{DynamicResource BaseComboBox}" TabIndex="20" ItemsSource="{Binding Path=AllDistricts, Mode=Default}" SelectedItem="{Binding Path=BodyTextDistrict, Mode=TwoWay}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding }"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>

        1 Reply Last reply
        0
        • B babongita

          I have a combobox where the ItemsSource is bound to a ObservableCollection and the SelectedItem is bound to a string DependencyProperty. The ObservableCollection is populated so that the first string is an string.empty, so that something by default is not selected. My problem is this, if I select something in the combobox beside the string.empty (by clicking the drop down arrow and left clicking on an item, you can click the drop down arrow and select the string.empty item. However you can use the scroll on the mouse and select the string.empty. Then the caveat is that you can not scroll with the mouse to something that is not string.empty, you have to hit the drop down arrow and select an item with a left mouse click. Any ideas, this has me stumped.

          P Offline
          P Offline
          pc rajesh singh
          wrote on last edited by
          #4

          I took your scenario and binded by creating the dependency property, for me everything works. Once the mouse is over the combo box and combobox has the focus , scrolling works fine with the mouse. you can only post a sample so that actual issue can be observed <ComboBox x:Name="cboDistrict" IsSynchronizedWithCurrentItem="True" Grid.Column="1" Grid.Row="0" Style="{DynamicResource BaseComboBox}" ItemsSource="{Binding Path=AllDistricts, Mode=Default}" SelectedItem="{Binding Path=BodyTextDistrict, Mode=TwoWay}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding }"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> Private Property AllDistricts() As ObservableCollection(Of String) Get Return DirectCast(GetValue(AllDistrictsProperty), ObservableCollection(Of String)) End Get Set(ByVal value As ObservableCollection(Of String)) SetValue(AllDistrictsProperty, value) End Set End Property Public Shared AllDistrictsProperty As DependencyProperty = _ DependencyProperty.Register("AllDistricts", GetType(ObservableCollection(Of String)), _ GetType(NameView), New UIPropertyMetadata(New ObservableCollection(Of String))) Public Property BodyTextDistrict() As String Get Return Convert.ToString(GetValue(BodyTextDistrictProperty)) End Get Set(ByVal value As String) SetValue(BodyTextDistrictProperty, value) End Set End Property Public Shared BodyTextDistrictProperty As DependencyProperty = _ DependencyProperty.Register("BodyTextDistrict", GetType(String), _ GetType(NameView), New UIPropertyMetadata(String.Empty))

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups