I am new to WPF.I have usercontrol which has expander and datagrid
in my UserControlViewModel
public ObservableCollection<MyResult> _results;
public UserControlViewModel
{
_results = new ObservableCollection<MyResult>();
_results.Add(new EntitySearchResults()
{
HeaderName= "Header1", //Expander header
ColName= new ObservableCollection<string>() { "Col1"}
CellValues = new ObservableCollection<string>() { "Val1" }
}
}
in my usercontrol.xaml
<DataGrid
x:Name="dataGrid"....
ItemsSource="{Binding Path=CellValues }"
SelectedValue="{Binding Path=SelectedValue,
RelativeSource={RelativeSource
FindAncestor,AncestorType=local:MyUserControl,
AncestorLevel=1}}" // This is Dependency Property which gets me the Datagrid Row
</DataGrid>
and In my Mainwindow I have
<DataTemplate>
<Grid>
<local:MyUserControl x:Name="mySearchControl"
SelectedValue="{Binding
DataContext.CurrentItem,ElementName=MyWindow,Mode=TwoWay}"/>
</Grid>
</DataTemplate>
and in my Mainwindow View Model
public object CurrentItem
{
get { return currentItem; }
set
{
currentItem = value;
SetProperty(ref currentItem, value);
}
}
But this just gives me the Row values.I also need the HeaderName and ColumnName in Mainwindow.
How can I do it ?