Answer the question
In order to leave comments, you need to log in
What is wrong with data binding?
Hello!
An error occurred while binding the data.
There are parent and child controls in which the SelectedIndex dependency property is implemented.
Next, in the parent control, I associate this property with the same property of the subordinate:
//this = currentObject;
//typeof(this) == typeof(Reader);
var indexBinding = new Binding();
indexBinding.Mode = BindingMode.TwoWay;
//указываю подчненный контролл как источник данных
indexBinding.Source = epubConrol.SelectedIndex;
//Очищаю свойство зависимостей и создаю привязку
currentObject.ClearValue(Reader.SelectedIndexProperty);
currentObject.SetBinding(Reader.SelectedIndexProperty, indexBinding);
Answer the question
In order to leave comments, you need to log in
For TwoWay, you must specify using Path or XPath.
Try like this:
//this = currentObject;
//typeof(this) == typeof(Reader);
var indexBinding = new Binding();
indexBinding.Mode = BindingMode.TwoWay;
//указываю подчненный контролл как источник данных
indexBinding.ElementName = "epubConrol";
indexBinding.Path = new PropertyPath("SelectedIndex");
//Очищаю свойство зависимостей и создаю привязку
currentObject.ClearValue(Reader.SelectedIndexProperty);
currentObject.SetBinding(Reader.SelectedIndexProperty, indexBinding);
<ListBox x:Name="lst1" SelectedIndex="{Binding ElementName=lst2, Path=SelectedIndex, Mode=TwoWay}">
<system:String>1 строка</system:String>
<system:String>2 строка</system:String>
</ListBox>
<ListBox Grid.Column="1" x:Name="lst2">
<system:String>1 строка</system:String>
<system:String>2 строка</system:String>
</ListBox>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question