Is it possible to give UserControl's Resources(Or one of its resource) as UserControl's DataContext?
I tried to bind a Button's Command Property in a DataGrid's CellTemplate to a property in my ViewModel.
If it were use a ListBox instead of DataGrid this works for me such as below,
<ListBox.ItemTemplate>
<DataTemplate>
<HyperlinkButton Content="{Binding DESCRIPTION}"
Command="{Binding DataContext.SelectSingleBackCommand, ElementName=LayoutRoot}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
But if I use DataGrid instead of ListBox even I Clicked the button there is no effect!
<data:DataGrid x:Name="RadGridSearchResults" ItemsSource="{Binding SearchResults}" AutoGenerateColumns="False" IsReadOnly="True">
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header="Just Header" CanUserSort="True" SortMemberPath="DESCRIPTION">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Margin="5" Content="{Binding DESCRIPTION}" Command="{Binding DataContext.SelectSingleBackCommand,ElementName=LayoutRoot}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
Then I thought there could be another LayoutRoot in DataGrid(Data Grid is a simple sl4 grid.) And changed LayoutRoot's name to LayoutRootMain. No way.
Note:Then I removed < UserControl.DataContext > part then,
So I decided to pass my ViewModel on < UserConrol.Resources > Part as shown below
<UserConrol.Resources>
<modelview:SelectReceiversViewModel x:Key="MainDataContextResource" x:Name="MainDataContextResource"/>
</UserControl.Resources>
But How can I bind UserControl's DataContext property to this resource, I tried;
<UserControl... DataContext="{Binding RelativeSource={RelativeSource Self},Path=Resources}"
Or
<UserControl... DataContext="{Binding ElementName=MainDataContextResource}"
Thanks!