c# - DataContext to DataGrid in user control -
i have main window tabcontrol. adding new tabitem user control content. in xaml:
<grid><datagrid datacontext="{binding path=patients, mode=twoway}"> <datagrid.columns> <datagridtextcolumn header="id" width="auto" binding="{binding id}"/>
in code behind: opening context,
var query = pp in context.patients select pp; var patients = query.tolist(); tabitem patientsview = new tabitem(); // adding new tabitem stackpanel header = new stackpanel header.children.add(new textblock {text="patients"}); patientsview.header = header; patientsview.content = new viewdatapatients{datacontext = patients};
it refuses populate bind data grid. idea doing wrong?
can't understand why need such approach, still. you've set datacontext of usercontrol patiense, datagrid alreay have data context, enought following:
<datagrid datacontext="{binding}">
but redundant in case. populate datagrid data set itemssource:
<datagrid itemssource="{binding}">
hope helps.
king regards, nazar