CellTemplateSelector-in-DataGrid-question

Nov 12, 2008 at 3:29 PM
Hallo,
I still need your help. I'd like to get a different image by using CellTemplateSelector.

What I'm trying to get is an item != null. Here item is always null.
The Type of the item I expect is DataRowItem or DataRow (from DataTable).

Thanks in advance.
WorstCase.

 

 

 

 

 

<UserControl.Resources>
<ResourceDictionary>

 

 

 

<local:TemplateSelector x:Key="dgTemplateSelector" />

 

 

 

<

 

DataTemplate x:Key="ItemImage">
<StackPanel Orientation="Horizontal">
<Image Height="24" Width="24" ToolTip ="OK" Source="Images\Status\StatusOK.ico" />
</StackPanel>
</DataTemplate>

 

 

 

</ResourceDictionary>
</UserControl.Resources>

 

 

 

<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn CellTemplateSelector="{StaticResource dgTemplateSelector}" Header="Rating" SortMemberPath="status" ClipboardContentBinding="{Binding customer_order_id}" />
</dg:DataGrid.Columns>


// C# Code
public class TemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
    {
        FrameworkElement fe = container as FrameworkElement;
        if (fe != null)
        {
            string s = "ItemImage";
            DataTemplate ret = fe.FindResource (s) as DataTemplate;
            return ret;
        }
        
DataTemplate dt = base.SelectTemplate (item, container);
        return dt;
    }
}