I have a observable collection in my view model like in the following.
private ObservableCollection<MyClass> _myData;
public ObservableCollection<MyClass> MyData
{
set { _myData=value; }
get { return _myData }
}
The structure of MyClas is like in the following.
class MyClass
{
private string name;
public string Name;
{
set { name=value;}
get { return name;}
}
}
I have binded the above observable collection to a combobox in my view like this.
<ComboBox Width="200"
ItemsSource="{Binding DataContext.MyData.Name,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
Still it says
BindingExpression path error: 'Name' property not found on 'object' ''ObservableCollection`1' (HashCode=22227061)'. BindingExpression:Path=DataContext.MyData.Name; DataItem='MyView' (Name=''); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
I find this strange. why does it say that Name property is not there in observable collection ?
Nameto something else, likeDNameand try...