Paolo
Paolo

Reputation: 627

WPF Editable Combobox does not change SelectedValue while typing

I defined a Combobox whose SelectedValue is binded to a property on the view model VM.SelectedServiceTypeId

<ComboBox Name="ServiceTypeComboBox"
          IsEditable="True"
          Grid.Row="1"
          Grid.Column="1"
          Margin="5"
          DisplayMemberPath="ServiceTypeName"
          ItemsSource="{Binding ServiceTypes,Mode=TwoWay}"
          SelectedValue="{Binding SelectedServiceTypeId, Mode=TwoWay}"
          SelectedValuePath="ServiceTypeId" 
          Loaded="ServiceTypeComboBox_Loaded"
          />

The value is correctly updated when the user selects an item in the dropdown menu, but cause the combobox IsEditable the user is able to type whatever he wants that it's not a value in the ItemSource. In this case the SelectedValue does NOT change.

What I need to do is to enable a button when the SelectedValue is among those in the ItemsSource.

Do you have some hint?

Upvotes: 1

Views: 986

Answers (2)

Maximus
Maximus

Reputation: 3448

<Button Content="Click">
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="IsEnabled" Value="True"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=ServiceTypeComboBox, Path=SelectedValue}" Value="{x:Null}">
                        <Setter Property="IsEnabled" Value="False"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

Upvotes: 0

Steven S.
Steven S.

Reputation: 734

Your wpf combobox has a property "Text" that contains the text input by the user. You will have to write some code to check if the entered text matches anything in your itemssource.

Upvotes: 3

Related Questions