Image inside rich text box inside radgridview gets changed

1 posts, 0 answers
  1. Muthu
    Muthu avatar
    8 posts
    Member since:
    Dec 2011

    Posted 02 Aug 2012 Link to this post

    I have rad grid view that will show set of properties. when two properties are images, on scrolling the gridview scrollbar, the first image is replaced by the second one
    I dont know why this is happening. I have attached the images.
    I am using CellStyleSelector for that column. The requirement is I have to use RichTextBox if that content is RichText and if that content ordinary text then i have to use Text Block

    This is how I created the CellStyleSelector

    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" &&
                    PropertyDetails.HasRichTextFormatting)
                {
                    return this.RichTextStyle;
     
                }
                else
                {
                    return this.TextBlockStyle;
                }
            }
        }

    And this is how I set the styles in Xaml
    <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 i implemented the RadGrid

    <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" CanUserFreezeColumns="False">
                    <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 x:Name="value" IsReadOnly="True" UniqueName="PropertyValue"
                                                    DataMemberBinding="{Binding values}" TextWrapping="Wrap"
                                                    CellStyleSelector="{StaticResource properyValueStyle}" >
                        </telerik:GridViewDataColumn>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>

    How can i avoid the replacement of content?
Back to Top