问题描述:

I have a textBox and I use a value converter to set the text property, because this value depends on the selección of a datagrid. So I use this code:

<TextBox Height="23" HorizontalAlignment="Stretch" Margin="5,26,0,0" Name="myTxt" VerticalAlignment="Top"

Text="{Binding ElementName=Principal, Path=DataContext.OneProperty, Converter={StaticResource myConverter}}">

Normallt I use this way:

Text="{Binding myProperty}"

But in this case I need a converter but also I would like to update a property in the dataContext.

Is that possible or if I use a converter I can't update a property in the dataContext?

Thanks.

EDIT:

I try to be a bit clerer.

I have a view that has a TextBox. I want to set this textBox according to a converter. This converter use a property in the view model called myDataGridSelectedItems. But I have other property in the view model called myTextBox that I want to be updated when the textBox update its value with the value that it receives from the converver.

So I want to binding the Text property of the view to two properties in the view model.

网友答案:

Yes you can. Implement the ConvertBack method in your value converter, which by the way should implement IValueConverter.

Also, specify the NotifyPropertyChanged binding's property to a on-key-press method.

And, the last thing, set the mode of binding to TwoWay.

相关阅读:
Top