Click here to Skip to main content
14,333,745 members

Silverlight / WPF

Chris Maunder16-Jul-09 3:09
adminChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 3:05
adminChris Maunder16-Jul-09 3:05 
QuestionDataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Mc_Topaz7-Oct-19 23:42
memberMc_Topaz7-Oct-19 23:42 
I have a DataGrid with a couple of DataGridTemplateColumns.
When I try to hit the Enter-key on my keyboard there is no new row created in the DataGrid.

I have other DataGrids with columns which are not DataGridTemplateColumns and I can then create new rows by hitting the Enter-key. So I assume the DataGridTemplateColumns in some way causing the problem.

I have made a reproducible code and I have made it public in this GIT-Gist.
* I use Fody PropertyChanged to handle all the INotificationPropertyChanged in my view models.
* The code should just be copy-and-paste.

The bindings between the View and the ViewModels also don't seem to work :S
But if you uncomment the row in the ViewModel's construcotor (please see line 60 in the MainWindow.xaml.cs), a new row in the DataGrid will be created. With this row, the bindings works as expected. I cannot understand why.

Here is the XAML-code. It maybe enough for you with only the XAML-code to solve this problem.
<Window x:Class="WpfApp1.MainWindow"







        Title="MainWindow" Height="450" Width="800">

        <local:ViewModel />
    <DataGrid ItemsSource="{Binding Rows}" AutoGenerateColumns="False" CanUserAddRows="True" Margin="0,50,0,0">

            <!-- Browse -->
            <DataGridTemplateColumn Header="Browse">
                        <Button Command="{Binding Browse}" Content="..." Width="40" Margin="6,0,6,0" />
            <!-- Path -->
            <DataGridTemplateColumn Width="300" Header="Path" IsReadOnly="True">
                        <TextBox Text="{Binding Path, Mode=OneWay}" />
            <!-- Slider -->
            <DataGridTemplateColumn Width="100" Header="Slider">
                        <Slider Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Minimum="1" Maximum="50" Margin="6,0,6,0" />

            <!-- Slider's value -->
            <DataGridTextColumn Binding="{Binding Value}" Header="Value" IsReadOnly="True" />



modified 8-Oct-19 7:33am.

AnswerRe: DataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Gerry Schmitz8-Oct-19 3:11
mveGerry Schmitz8-Oct-19 3:11 
NewsRe: DataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Mc_Topaz8-Oct-19 3:25
memberMc_Topaz8-Oct-19 3:25 
QuestionWPF Pin
Member 145835423-Oct-19 22:29
memberMember 145835423-Oct-19 22:29 
AnswerRe: WPF Pin
Richard Deeming4-Oct-19 1:59
mveRichard Deeming4-Oct-19 1:59 
AnswerRe: WPF Pin
Richard MacCutchan4-Oct-19 3:22
protectorRichard MacCutchan4-Oct-19 3:22 
AnswerRe: WPF Pin
Gerry Schmitz4-Oct-19 6:32
mveGerry Schmitz4-Oct-19 6:32 Pin
Member 1458354220-Sep-19 21:27
memberMember 1458354220-Sep-19 21:27 
AnswerRe: Pin
Richard MacCutchan21-Sep-19 2:58
protectorRichard MacCutchan21-Sep-19 2:58 Pin
Member 1458354220-Sep-19 20:09
memberMember 1458354220-Sep-19 20:09 
AnswerRe: Pin
Richard MacCutchan20-Sep-19 21:07
protectorRichard MacCutchan20-Sep-19 21:07 
AnswerRe: Pin
Mycroft Holmes21-Sep-19 12:48
memberMycroft Holmes21-Sep-19 12:48 
QuestionHow to use DataTrigger to run Storyboard? Pin
Pew_new20-Sep-19 8:00
memberPew_new20-Sep-19 8:00 
QuestionWPF Pin
Member 1458354219-Sep-19 2:35
memberMember 1458354219-Sep-19 2:35 
AnswerRe: WPF Pin
Richard Deeming19-Sep-19 2:58
mveRichard Deeming19-Sep-19 2:58 
AnswerRe: WPF Pin
Mycroft Holmes19-Sep-19 13:07
memberMycroft Holmes19-Sep-19 13:07 
QuestionWindow Not Refreshing Pin
Kevin Marois17-Sep-19 9:03
professionalKevin Marois17-Sep-19 9:03 
AnswerRe: Window Not Refreshing Pin
Richard Deeming17-Sep-19 9:34
mveRichard Deeming17-Sep-19 9:34 
GeneralRe: Window Not Refreshing Pin
Kevin Marois17-Sep-19 10:03
professionalKevin Marois17-Sep-19 10:03 
GeneralRe: Window Not Refreshing Pin
Richard Deeming18-Sep-19 0:44
mveRichard Deeming18-Sep-19 0:44 
QuestionWPF Pin
Member 145835429-Sep-19 19:20
memberMember 145835429-Sep-19 19:20 
AnswerRe: WPF Pin
Richard MacCutchan9-Sep-19 21:19
protectorRichard MacCutchan9-Sep-19 21:19 
QuestionWPF Pin
Member 145835429-Sep-19 0:25
memberMember 145835429-Sep-19 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.