This is a migrated thread and some comments may be shown as answers.

Dynamic Cell Template

1 Answer 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
StevenDale
Top achievements
Rank 2
StevenDale asked on 05 Apr 2012, 09:48 PM

Q1 2012

I have a RadGridView that I am binding to a DataTable. The DataTable is dynamically generated in code. In the first column of the DataTable there is an object. I have an event attached to the RowLoaded event. In the RowLoaded event I want to set the template of the first cell to a Resource Template. This is the code I am using but the cell is always empty.

XAML Template

<ControlTemplate x:Key="FluidEditorTemplate">
                <shared:PopupButton PopupHorizontalOffset="0" HorizontalContentAlignment="Left" BorderThickness="0" BorderBrush="Transparent" PopupContent="{Binding}" Foreground="Black"  FontWeight="Bold" VerticalContentAlignment="Center" Margin="0,0,10,0" Background="Transparent" IsRounded="True" Grid.Column="1" Grid.Row="1" DisplayMode="Merged" >
                    <shared:PopupButton.PopupContentTemplate>
                        <DataTemplate>
                            <StackPanel Background="DarkGray" >
                                <Button ToolTip="Cancel" Tag="{Binding}" Style="{DynamicResource GreenGlassButtonStyle}" Margin="2" Height="24"  Width="110" Foreground="White" Content="Cancel" HorizontalAlignment="Right" />
                                <Button ToolTip="Modify" Tag="{Binding}" Style="{DynamicResource RedGlassButtonStyle}" Margin="2" Height="24" Width="110" Foreground="White" Content="Modify" HorizontalAlignment="Right"  />
                                <Button ToolTip="Stop" Tag="{Binding}" Style="{DynamicResource RedGlassButtonStyle}" Margin="2" Height="24" Width="110" Foreground="White" Content="Stop" HorizontalAlignment="Right"  />
                            </StackPanel>
                        </DataTemplate>
                        </shared:PopupButton.PopupContentTemplate>
                </shared:PopupButton>
            </ControlTemplate>

XAML GridView

<telerik:RadGridView RowLoaded="FluidsGridRowLoaded"Grid.Row="1" AutoGenerateColumns="True" ItemsSource="{Binding FluidsDataSource}" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" />

Code

private void FluidsGridRowLoaded(object sender, RowLoadedEventArgs e)
{
    if (!DesignerProperties.GetIsInDesignMode(this))
    {
        if (e.Row.Cells.Count > 0)
            e.Row.Cells[0].Template = Application.Current.Resources["FluidEditorTemplate"] as ControlTemplate;
    }
}

Thanks,

Billy Jacobs



1 Answer, 1 is accepted

Sort by
0
StevenDale
Top achievements
Rank 2
answered on 05 Apr 2012, 10:11 PM
I figured out the problem. The resource was null. I had to name the grid that the resources were contained within and then access the resource through it like so:

private void FluidsGridRowLoaded(object sender, RowLoadedEventArgs e)
{
    if (!DesignerProperties.GetIsInDesignMode(this))
    {
        if (e.Row.Cells.Count > 0)
        {
            ControlTemplate template = _fluidsGrid.Resources["FluidEditorTemplate"] as ControlTemplate;
            e.Row.Cells[0].Template = template;
        }
    }
}
Tags
GridView
Asked by
StevenDale
Top achievements
Rank 2
Answers by
StevenDale
Top achievements
Rank 2
Share this question
or