Problem with WPF Combobox
-
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.
-
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.
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:
-
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:
<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>
-
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.
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))