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

Image inside Rich Text box inside grid view is changing while scroll

0 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Muthu
Top achievements
Rank 1
Muthu asked on 03 Aug 2012, 05:57 AM
we are displaying some property details in a rad grid.
The Property value has some TExt values and rich text content.
We have to use Appropriate control based on the content type so we use cell style selector to select the template based on the data type.
But while scrolling down and up the first image is replaced by the second one.
Please help on avoiding this issue.

We use the following code for cell style selector
public class PropoertyValueStyleSelector : StyleSelector
    {
        public Style RichTextStyle
        {
            get;
            set;
        }
 
        public Style TextBlockStyle
        {
            get;
            set;
        }
 
        public override Style SelectStyle(object item, DependencyObject container)
        {
            var PropertyDetails = item as PropertyDetails;
 
            if (PropertyDetails != null &&
                PropertyDetails.dataType == "RICHTEXT")
            {
                return this.RichTextStyle;
 
            }
            else
            {
                return this.TextBlockStyle;
            }
        }
    }

this is how we set style for the style selector
<local:PropoertyValueStyleSelector x:Key="properyValueStyle">
            <local:PropoertyValueStyleSelector.RichTextStyle>
                <Style TargetType="telerik:GridViewCell">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <telerik:RadRichTextBox IsSpellCheckingEnabled="False" BorderBrush="{x:Null}"
                                                        BorderThickness="0" x:Name="richText" IsReadOnly="True"
                                                        HyperlinkNavigationMode="Click"
                                                        HorizontalAlignment="Left" VerticalAlignment="Center"
                                                        HyperlinkClicked="richText_HyperlinkClicked">
                                    <telerik:RadRichTextBox.Resources>
                                        <telerikHTML:HtmlDataProvider RichTextBox="{Binding ElementName=richText}"
                                                                      Html="{Binding value}"  x:Key="richText"/>
                                    </telerik:RadRichTextBox.Resources>
                                </telerik:RadRichTextBox>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </local:PropoertyValueStyleSelector.RichTextStyle>
            <local:PropoertyValueStyleSelector.TextBlockStyle>
                <Style TargetType="telerik:GridViewCell">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock FontWeight="Normal" Text="{Binding value}" HorizontalAlignment="Left"
                                           VerticalAlignment="Center" TextWrapping="Wrap"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </local:PropoertyValueStyleSelector.TextBlockStyle>
        </local:PropoertyValueStyleSelector>

And this is how we implemented the Rad Grid
<telerik:RadGridView x:Name="newGrdDetails" ShowColumnHeaders="False" AutoGenerateColumns="False"
                                 ShowGroupPanel="False" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                 ScrollViewer.VerticalScrollBarVisibility="Auto"                                 
                                 IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed"
                                 Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                 Grid.Row="2" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="Gray"
                                 SelectionUnit="Cell" SelectionMode="Extended">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="PropertyName"
                                                DataMemberBinding="{Binding name}" Width="200"  TextWrapping="Wrap" >
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding name}"  Width ="Auto" VerticalAlignment="Top"
                                           TextWrapping="Wrap">
                                    <ToolTipService.ToolTip>
                                        <TextBlock Text="{Binding description}" TextWrapping="Wrap" MaxWidth="400"/>
                                    </ToolTipService.ToolTip>
                                </TextBlock>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="PropertyValue"
                                                DataMemberBinding="{Binding value}" TextWrapping="Wrap"
                                                CellStyleSelector="{StaticResource properyValueStyle}" >
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

Please help us to avoid this issue.

I have attached the screen shots

Thanks,
Muthu
Tags
GridView
Asked by
Muthu
Top achievements
Rank 1
Share this question
or