0
votes

I have a combobox with the SelectedItem property bound to a DataRowView and the ItemSource to a DataView.

The binding is like this:

   <ComboBox Grid.Row="1" Grid.Column="1" KeyboardNavigation.TabIndex="0" Width="300"
              ItemsSource="{Binding Path=MainConfigItems, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
            SelectedValuePath="Id" 
              DisplayMemberPath="Name"
              SelectedItem="{Binding MainConfigSelectedItem}"
              Name="cmbBoxMainConfig"
             VerticalAlignment="Center" HorizontalAlignment="Left" IsEnabled="{Binding IsEnabledMainConfig}">
  </ComboBox>

Now, based on a condition, I need to hide the combobox and display a textbox in its place with text as the display member of the combobox. In this case, the 'Name' attribute of the DataRowView.

What would be the best way to do this?

2

2 Answers

0
votes

put a datatrigger on your combo and textbox:

<ComboBox.Style>
   <Style TargetType="ComboBox">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Path=IsEnabledMainConfig, UpdateSourceTrigger=PropertyChanged}" Value="false" >
        <Setter Property="Visibility" Value="Hidden"/>
        </DataTrigger>
      </Style.Triggers>
  </Style>
</ComboBox.Style>
0
votes
<TextBox Text="{Binding MainConfigSelectedItem.Name}"/>

if MainConfigSelectedItem is a DataRowView you need to use the indexer in your binding ( MainConfigSelectedItem[Name]).

i would use style trigger to change visibility.