0

I got a TextBox here

<TextBox ...> <TextBox.Text> <Binding Path="MinStepDiff" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <local:ImpellerArgsRule IsCanBeZero ="false"/> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox> 

It's Content is rely on other ComboBox

<ComboBox ...> <ComboBoxItem Content="Sample1"/> <ComboBoxItem Content="Sample2"/> <ComboBoxItem Content="Sample3"/> </ComboBox> 

If Sample1 or Sample3 is chosen, the TextBox should be bind to MinStepDiff

If Sample2 is chosen, the TextBox should be bind to MinTolerance then

Both of them are properties of an object.

How can I do it?

1
  • I suppose you can try to use multibinding and a custom converter to select the appropriate value. You can find some information about multibinding here: stackoverflow.com/questions/260439/…. Commented May 19, 2012 at 12:24

1 Answer 1

1

You could use a DataTrigger. For this you have to create a style and give your ComboBox a name (here 'cb'). Because it's easier I bound to SelectedIndex instead of SelectedItem.

<TextBox> <TextBox.Style> <Style TargetType="TextBox"> <Setter Property="Text"> <Setter.Value> <Binding Path="MinStepDiff" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <local:ImpellerArgsRule IsCanBeZero="false" /> </Binding.ValidationRules> </Binding> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding SelectedIndex, ElementName=cb}" Value="1"> <Setter Property="Text"> <Setter.Value> <Binding Path="MinTolerance" UpdateSourceTrigger="PropertyChanged" /> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.