Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:37:42+00:00 2026-06-17T23:37:42+00:00

My goal is creating an inplace editor in WPF datagrid column to edit large

  • 0

My goal is creating an inplace editor in WPF datagrid column to edit large texts.

My datasource is a DataTable that can contain data from different tables and fields, that’s why i have no any defined types to bind to. In my example it has 1 column named “Test”.
Now i wrote some XAML code to define my column:

<ControlTemplate x:Key="ExtendedTemplate">
    <StackPanel>
        <TextBox Text="{Binding Test}" Width="200" Height="100" AcceptsReturn="True" TextWrapping="Wrap"/>
    </StackPanel>
</ControlTemplate>                

<DataGrid x:Name="grid" ItemsSource="{Binding}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="TEST Column" Width="200">
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <ComboBox IsDropDownOpen="True">
                        <ComboBoxItem Template="{StaticResource ExtendedTemplate}"/>
                    </ComboBox>
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Test}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

Here is my test datasource:

Source = new DataTable("Test");
Source.Columns.Add("Test");
Source.Rows.Add("Item 1 - large amount of text ...");
Source.Rows.Add("Item 2");
Source.Rows.Add("Item 3");
grid.DataContext = Source;

This works fine, but the last thing i need to do is to decorate grid cell while it is in edit mode and i’m typing text in expanded combo:

Screenshot

It is important:
First – combobox isn’t binded to any ItemsSource, but single ComboBoxItem exists for any cell and contains text from that cell.

Second – i can’t define DataTemplate to SelectedItem because ComboBox.SelectionBoxItemTemplate Property is read only.

Does anybody know how can i replace datatemplate for SelectionBoxItem to something like this?

<DataTemplate>
    <TextBlock Text="{Binding Test}"/>
</DataTemplate>

I tried to create custom style for combobox with command “Edit template – Edit a copy…”. There is a lot of markup and i don’t want to post it here. Here is a small part edited by me.

<ContentPresenter ContentTemplate="{StaticResource SimplestTemplate}" 
                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" 
                  Content="{TemplateBinding SelectionBoxItem}" 
                  ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                  IsHitTestVisible="false"
                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                  VerticalAlignment="Stretch"
                  HorizontalAlignment="Stretch"/>

It doesn’t work, because id don’t know how to write my “SimplestTemplate” that should bind data to my “Test” field.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:37:43+00:00Added an answer on June 17, 2026 at 11:37 pm

    I achieved my goal by creating a style, derived from ComboBox, and overriding its ContentPresenter ContentTemplate. It works ok, but i stopped my work on it, because there are many additional features, that need to be implemented (such as resizing popup editor, automatic grid cell refreshing, assigning commands to hotkeys to work with editor with keyboard only etc.). At last i decide to use third-party component (this one).

    As an answer to my question i post my final XAML markup:

    Resources:

    <Window.Resources>
    
        <DataTemplate x:Key="SimplestTemplate">
            <Grid>
                <TextBlock Background="White" Foreground="Black" Text="{TemplateBinding Content}"/>
            </Grid>
        </DataTemplate>
    
        <ControlTemplate x:Key="ExtendedTemplate">
            <StackPanel>
                <TextBox Text="{Binding Test}" MinHeight="100" Height="Auto" MinWidth="{TemplateBinding Width}" Width="{Binding MinWidth}" TextWrapping="Wrap"/>
            </StackPanel>
        </ControlTemplate>                
    
        <Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Grid x:Name="MainGrid" SnapsToDevicePixels="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                                <Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
                                    <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                                        <ScrollViewer x:Name="DropDownScrollViewer">
                                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                                <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                                    <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
                                                </Canvas>
                                                <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                            </Grid>
                                        </ScrollViewer>
                                    </Border>
                                </Themes:SystemDropShadowChrome>
                            </Popup>
                            <ContentPresenter ContentTemplate="{StaticResource SimplestTemplate}"
                                              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" 
                                              Content="{TemplateBinding help:ComboboxHelper.BindedText}" 
                                              ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"                                               
                                              IsHitTestVisible="false"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              VerticalAlignment="Stretch"
                                              HorizontalAlignment="Stretch"
                                              Grid.ColumnSpan="2"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>      
    </Window.Resources>
    

    Grid column template:

    <DataGridTemplateColumn Header="TEST Column" Width="200">
        <DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <ComboBox IsDropDownOpen="True" Style="{StaticResource MyComboBoxStyle}" FocusVisualStyle="{x:Null}" help:ComboboxHelper.BindedText="{Binding Test}">
                    <ComboBoxItem Template="{StaticResource ExtendedTemplate}"/>
                </ComboBox>
            </DataTemplate>
        </DataGridTemplateColumn.CellEditingTemplate>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Test}" TextTrimming="CharacterEllipsis"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    

    To show clipped text in cell i created a simple attached property. It cuts all "\n" symbols in text to make it single-line.

    public static class ComboboxHelper
    {
        public static readonly DependencyProperty BindedTextProperty = DependencyProperty.RegisterAttached("BindedText", typeof(string), typeof(ComboboxHelper));
    
        public static string GetBindedText(DependencyObject obj)
        {
            string s = (string)obj.GetValue(BindedTextProperty);
            s = s.Replace(Environment.NewLine, " ");
            return s;
        }
    
        public static void SetBindedText(DependencyObject obj, string value)
        {
            obj.SetValue(BindedTextProperty, value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application that uses Qt 4.7 with the goal of creating a
I am creating a page that a user can click a link and it
I am creating domain model. I have Goal ( something that user wants to
I have a high-level goal of creating a static utility class that encapsulates the
I am creating a DataTable at runtime. My goal is to insert an image
The Goal I want to select <td> elements that contain only a checkbox. I
Goal : I wants when I drag image it become fade so we can
Goal is to make a dialog that appears on menu_key pressed, but it keeps
Goal: Produce an Excel document with information from 3 associated models that is similar
Goal: to create a percentage column based off the values of calculated columns. Here's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.