Display XAML element in GridViewDataColumn

1 Answer 23 Views
GridView
Yowims
Top achievements
Rank 1
Iron
Yowims asked on 13 Jun 2022, 09:02 AM | edited on 13 Jun 2022, 09:03 AM

Hi,

I made a table using RadGridView and in one of my columns I wanna have another XAML element insted of having text.
I have columns like this one : 

<telerik:GridViewDataColumn UniqueName="NameColumn"
                                                x:Name="NameColumn"
                                                Width="*" 
                                                TextAlignment="Left"
                                                Header="{Resx Common_Label}"
                                                MinWidth="200"
                                                DataMemberBinding="{Binding TankName}"
                                                IsFilterable="False">
                    <telerik:GridViewColumn.CellStyle>
                        <Style TargetType="telerik:GridViewCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Border BorderBrush="LightBlue" BorderThickness="0 0 1 0">
                                            <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" TextAlignment="Left" Margin="20, 0, 0, 0" Text="{Binding TankName}" FontFamily="Segoe UI" FontSize="16" />
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </telerik:GridViewColumn.CellStyle>
</telerik:GridViewDataColumn>
And I wanna do something like that :

<telerik:GridViewDataColumn UniqueName="ErrorColumn"
                                            x:Name="ErrorColumn"
                                            Width="*"
                                            MinWidth="200"
                                            IsFilterable="False">
                    <common:ErrorDiode x:Name="DiodeError" ></common:ErrorDiode>
</telerik:GridViewDataColumn>

And Visual Studio shows me an error saying that's impossible to have direct content in GridViewDataColumn.

What should I do?

1 Answer, 1 is accepted

Sort by
0
Accepted
Yowims
Top achievements
Rank 1
Iron
answered on 13 Jun 2022, 09:38 AM
Okay I'm dumb, problem solved by putting my XAML element in a ControlTemplate just like the other columns ^^'

<telerik:GridViewDataColumn UniqueName="ErrorColumn"
                                            x:Name="ErrorColumn"
                                            Width="*"
                                            IsFilterable="False">
                    <telerik:GridViewColumn.CellStyle>
                        <Style TargetType="telerik:GridViewCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <common:ErrorDiode x:Name="DiodeError" ></common:ErrorDiode>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </telerik:GridViewColumn.CellStyle>
</telerik:GridViewDataColumn>

Tags
GridView
Asked by
Yowims
Top achievements
Rank 1
Iron
Answers by
Yowims
Top achievements
Rank 1
Iron
Share this question
or