Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
Making editor work on overwritten CellValuePresenter style
posted

I have a column that uses an IValueConverter to change the text.  I'm using a style to insert a TextBlock to display this updated text in the cell.  In my first attempt, I made a very simple style, just containing the TextBlock.  As I've discovered, at a minimum, a ContentPresenter named PART_EditorSite needs to be in the style to get editting to work. I've attempted to copy the entire style over from the built-in styles to get the editor to display.  The result is below; both the editor and textblock display at the same time while in view mode.  While in edit-mode, the textblock does remain visible, but it is almost completely covered by the editor.

           

 

I copied the style from DataPresenterGeneric_Express.xaml

Here is the style:

    <Style x:Key="StrikeStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}">
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                    <igWindows:CardPanel>
                        <Border
                            x:Name="MainBorder"
                            CornerRadius="{TemplateBinding CornerRadius}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Background="{TemplateBinding Background}"/>
                        <TextBlock x:Name="Active"
                            Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StrikeConverter}}"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Width="Auto"
                            Height="Auto"
                            SnapsToDevicePixels="True"
                            Opacity="1"/>
                        <ContentPresenter
                            x:Name="PART_EditorSite"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}"
                            Style="{TemplateBinding ForegroundStyle}"                            
                        />
                    </igWindows:CardPanel>
                    <ControlTemplate.Triggers>
                        <!-- HighlightAsPrimary -->
                        <Trigger Property="HighlightAsPrimary" Value="true">
                            <Setter Property="Background" Value="{Binding Path=BackgroundPrimary, RelativeSource={RelativeSource Self}}"/>
                            <Setter Property="BorderBrush" Value="{Binding Path=BorderPrimaryBrush, RelativeSource={RelativeSource Self}}"/>
                            <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundPrimaryStyle, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Trigger>
                        <!-- IsFieldSelected -->
                        <Trigger Property="IsFieldSelected" Value="true">
                            <Setter Property="Background" Value="{Binding Path=BackgroundFieldSelected, RelativeSource={RelativeSource Self}}"/>
                            <Setter Property="BorderBrush" Value="{Binding Path=BorderFieldSelectedBrush, RelativeSource={RelativeSource Self}}"/>
                            <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundFieldSelectedStyle, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Trigger>
                        <!-- IsSelected -->
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="{Binding Path=BackgroundSelected, RelativeSource={RelativeSource Self}}"/>
                            <Setter Property="BorderBrush" Value="{Binding Path=BorderSelectedBrush, RelativeSource={RelativeSource Self}}"/>
                            <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundSelectedStyle, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <!--<Setter Property="Visibility" Value="Visible" TargetName="LeftBorder" />-->
                        </Trigger>
                        <!-- IsActive -->
                        <Trigger Property="IsActive" Value="true">
                            <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundActiveStyle, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter Property="Visibility" TargetName="Active" Value="Visible"/>
                        </Trigger>
                        <!-- IsMouseOver -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"/>
                                <Condition Property="IsSelected" Value="False"/>
                                <Condition Property="IsFieldSelected" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{Binding Path=BackgroundHover, RelativeSource={RelativeSource Self}}"/>
                            <Setter Property="BorderBrush" Value="{Binding Path=BorderHoverBrush, RelativeSource={RelativeSource Self}}"/>
                            <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundHoverStyle, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </MultiTrigger>
                        <!-- Field.IsFixedStateChanging    JM 01-22-09 NA 9.1 FixedFields   -->
                        <DataTrigger Binding="{Binding Path=Field.IsFixedStateChanging, RelativeSource={RelativeSource Self}}" Value="True">
                            <Setter Property="Background" Value="#AA8DBAEB"/>
                            <Setter Property="BorderBrush" Value="#AA8DBAEB"/>
                        </DataTrigger>
                        <!--SSP 5/27/09 NAS9.2 IDataErrorInfo Support-->
                        <Trigger Property="IsDataErrorTemplateActive" Value="true">
                            <Setter TargetName="PART_EditorSite" Property="ContentTemplate" Value="{DynamicResource {x:Static igDP:DataPresenterBase.DataErrorContentTemplateKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <!-- DRCA Foreground Hover Trigger-->

            <!-- JJD 4/30/09 - TFS17157 use new IsRecordSelected property -->
            <Trigger Property="IsRecordSelected" Value="True">
                <Setter Property="ForegroundStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" />
            </Trigger>

            <!-- DRCA Foreground Selected Trigger-->
            <!-- JJD 4/30/09 - TFS17157 use new IsMouseOverRecord property -->
            <Trigger Property="IsMouseOverRecord" Value="True">
                <Setter Property="ForegroundStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" />
            </Trigger>

        </Style.Triggers>
    </Style>

 

The only change I made was replacing the Rectangle with the TextBlock.

Original:

<Rectangle x:Name="Active" Fill="{TemplateBinding BackgroundActive}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SnapsToDevicePixels="True" Opacity="1" Visibility="Collapsed" StrokeThickness="1" Stroke="{TemplateBinding BorderActiveBrush}"/>

Changed to: 

<TextBlock x:Name="Active" Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StrikeConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Width="Auto" Height="Auto" SnapsToDevicePixels="True" Opacity="1"/>

 

Parents Reply Children
No Data