How to reuse my customize DataGridTemplateColumn

Apr 20, 2009 at 9:54 AM
Hi, I have one DataGridTemplateColumn as below, and it will be reused in several my datagrids, so I would like to make it can be easy to resued. 

Since in the DataTemplate, there's one click event in just one button, so it's hard to put it to ResourceDictionary as one DataTemplate. 

So I try to put it in a user control, but it reported cannot be added to a collection or dictionary of type 'ObservableCollection`1' when I try to use it from a UserControl. I don't understand the reason.
 
Anyone has better idea how to reuse it? Thanks very much


                <dg:DataGridTemplateColumn Header="Output"  Width="180">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Name="txtOutput" Text="{Binding Path=OutputFile, UpdateSourceTrigger=PropertyChanged}"/>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Path=IsFileInGroup}" Value="TRUE">
                                    <Setter Property="Visibility" TargetName="txtOutput" Value="Hidden"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <DockPanel Name="panelOutput" HorizontalAlignment="Stretch">
                                <Button Content="..." Width="30" DockPanel.Dock="Right" Click="btnSelectOutputPath"/>
                                <TextBox HorizontalContentAlignment="Stretch">
                                    <TextBox.Text>
                                        <Binding Path="OutputFile" UpdateSourceTrigger="PropertyChanged">
                                            <Binding.ValidationRules>
                                                <l:OutputValidationRule/>
                                            </Binding.ValidationRules>
                                        </Binding>
                                    </TextBox.Text>
                                </TextBox>
                            </DockPanel>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Path=IsFileInGroup}" Value="TRUE">
                                    <Setter Property="Visibility" TargetName="panelOutput" Value="Hidden"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                </dg:DataGridTemplateColumn>
Jun 1, 2009 at 11:17 AM

Hi,

me 2 hanging on same kind of scenario.

Have you got any idea for it.

Regards,

Prabakaran S.