0
votes

I made a custom DataGridColumn (DGNumericColumn) with an editing element of type NumericUpDown (taken from the Extended WPF toolkit)

<k:DataGrid ItemsSource="{Binding Profiles}" 
            SelectedIndex="{Binding SelectedProfile}">
  <k:DataGrid.Columns>
    <k:DGNumericColumn Binding="{Binding Depth}"/>
    .
    .
    .

What I want is (what everybody wants from datagrid :)), is to, for example, update the Depth property in the ViewModel, in a way similar to what happens when NumericUpDown control is not "inside" a DataGrid, e.g. when the value of the control is changed and not only when the cell changes (CellEditEnding event). I thought that the following could might work, but it didn't.

<k:DataGrid ItemsSource="{Binding Profiles}" 
            SelectedIndex="{Binding SelectedProfile}">
  <k:DataGrid.Columns>
    <k:DGNumericColumn>
      <k:DGNumericColumn.EditingElementStyle>
        <Style TargetType="j:NumericUpDown">
          <Setter Property="Value" Value="{Binding Depth}"/>
          <Setter Property="Maximum" Value="10.0"/>
        </Style>
      </k:DGNumericColumn.EditingElementStyle>          
    </k:DGNumericColumn>
    .
    .
    .

Keep in mind that the maximum threshold in the style works, and no binding problems are reported in the output area of Visual Studio. How to solve the problem of property changing only when the cell loses its focus?

1
Please post your answer AS an answer, so it can be upvoted and accepted. Otherwise, this question will appear to be unanswered. :)Dan J
@djacobson ok, i dont have the credentials to write my own answer fast enough.Dimi_Pel

1 Answers

0
votes

Ok, solved.

<k:DataGrid ItemsSource="{Binding Profiles}" 
            SelectedIndex="{Binding SelectedProfile}">   
  <k:DataGrid.Columns>
    <k:DataGridTemplateColumn>
      <k:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Depth}"/>
        </DataTemplate>
      </k:DataGridTemplateColumn.CellTemplate>
      <k:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
          <l:NumericUpDown Value="{Binding Depth}"/>
        </DataTemplate>
      </k:DataGridTemplateColumn.CellEditingTemplate>
    </k:DataGridTemplateColumn>
    .
    .
    .