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
295
Allow Copy along with bubbling click event from textbox in a CellValuePresenter to Grid
posted

Hi,

I have a xamgrid with cell value presenter as posted below. 

I tried to use the inbuilt Copy functionality but it seems to copy the Content of the cell rather than the displayed value and it also doesn't allow selecting a part of the text and copying it to the clipboard. I achieved this for a selected cell by binding the CTRL+C gesture.

Since the above solution is not providing me the functionality i want, I changed the CellValue presenter to display the content using a textbox (styled liked a textblock) so that users can copy all or part of the presented data from the cell.

Now i can selectively copy text from the cell, but if i click on the textbox area of the cell, the click is not registered with the grid. Now i have to be careful as to where i am clicking to get the intended behavior like highlighting the record or firing an event to fetch child records as a result of the click. 

How can I implement a solution where

  • Users can copy and paste all or part of the data from a cell
  • Highlight the cell as selected (Show some visual adorner like a dotted rectangle)
  • Highlight the record as selected (So even if a user is clicking on a cell the entire row has to be high lighted in addition to the fact the cell also has an adorned showing that it is the selected cell)
  • Fire the SelectedItemsChanged event in the grid

My Current Cell Value Presenter style below. This cell value presenter is attached to a unbound field which is generated dynamically and added to the field layout. Any help is greatly appreciated.

<Style x:Key="DynamicBackgroundCellStyle" TargetType="{x:Type igDP:CellValuePresenter}">

      <Setter Property="OverridesDefaultStyle" Value="True"/>
      <Setter Property="Foreground" Value="{DynamicResource Foreground}"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
            <Grid Margin="5,0,5,0">
              <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
              </Grid.RowDefinitions>
                <Grid>
                  <ContentPresenter Panel.ZIndex="1"
                        Margin="4"
                        VerticalAlignment="Center"
                        x:Name="contentPresenter">
                  <ContentPresenter.Style>
                    <Style TargetType="{x:Type ContentPresenter}">
                      <Setter Property="HorizontalAlignment" Value="Left"/>
                      <Style.Triggers>
                        <Trigger Property="Content"  Value="-">
                          <Setter Property="HorizontalAlignment" Value="Center"/>
                        </Trigger>
                      </Style.Triggers>
                    </Style>
                  </ContentPresenter.Style>
                  <ContentPresenter.Content>
                      <MultiBinding Converter="{StaticResource BucketDataToUtilizationConverter}" ConverterParameter="$">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content" />
                      </MultiBinding>
                    </ContentPresenter.Content>

                  <ContentPresenter.ContentTemplate>

                    <DataTemplate>

                      <TextBox IsReadOnly="True" Background="Transparent" Foreground="{DynamicResource Foreground}"

                                                            BorderThickness="0" Text="{Binding Mode=OneWay}" />

                    </DataTemplate>

                  </ContentPresenter.ContentTemplate>

                </ContentPresenter>
                  <Border Panel.ZIndex="0" HorizontalAlignment="Left">
                    <Border.Width>
                      <MultiBinding Converter="{StaticResource BucketDataToCellBackgroundWidthConverter}" ConverterParameter="-10">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content"/>
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Field.CellWidthResolved" />
                      </MultiBinding>
                    </Border.Width>
                    <Border.Background>
                      <LinearGradientBrush>
                        <GradientStop Offset="0" >
                          <GradientStop.Color>
                            <MultiBinding Converter="{StaticResource BucketDataToAlertColorConverter}">
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content"/>
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Field.CellWidthResolved" />
                            </MultiBinding>
                          </GradientStop.Color>
                        </GradientStop>
                        <GradientStop Offset="0.5" >
                          <GradientStop.Color>
                            <MultiBinding Converter="{StaticResource BucketDataToAlertColorConverter}">
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content"/>
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Field.CellWidthResolved" />
                            </MultiBinding>
                          </GradientStop.Color>
                        </GradientStop>
                        <GradientStop Offset="1" >
                          <GradientStop.Color>
                            <MultiBinding Converter="{StaticResource BucketDataToAlertColorConverter}" ConverterParameter="fade">
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content"/>
                              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Field.CellWidthResolved" />
                            </MultiBinding>
                          </GradientStop.Color>
                        </GradientStop>
                      </LinearGradientBrush>
                    </Border.Background>
                  </Border>
                </Grid>
              <TextBlock Grid.Row="1"
                    Margin="5,0,5,5"
                    Foreground="{DynamicResource Foreground}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center">
                    <TextBlock.Text>
                      <MultiBinding Converter="{StaticResource HighWaterMarkConverter}" ConverterParameter="$">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.DataItem" />
                      </MultiBinding>
                    </TextBlock.Text>
              </TextBlock>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

Thanks

Shahin