简体   繁体   中英

How to enable/disable TextBox according to ComboBox in ListView

Is it possible to enable/disable TextBox according to ComboBox selected value (for example enable it if selected value is "From To"?

<ListView Height="120" HorizontalAlignment="Left" Margin="19,92,0,0"
          VerticalAlignment="Top" Width="500" 
          SelectionMode="Multiple"
          ItemsSource="{Binding Products}">
    <ListView.View>
        <GridView>
            <!--another columns-->
            <GridViewColumn Header="Selection Mode">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Width="70" Name="SelectionMode">
                            <ComboBoxItem Content="From To" IsSelected="True" />
                            <ComboBoxItem Content="List" />
                        </ComboBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox Width="70"></TextBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

I'd suggest that you use ComboBoxItem's values as opposed to content. You'll need to write a binding which will bind your combobox SelectedValue (see my suggestion) to Enabled of your textbox. The binding will use a converter ( IValueConverter ), which will return True or False depending on SelectedValue value passed in - based on your query if SelectedValue == 'FromTo' , your converter will return True , otherwise False .

I'd also suggest that you use objects, backing your UI elments, which is by all means a cleaner way of doing things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM