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
320
XamTextEditor Cell not starting in EditMode on Tab
posted

I have a wpf View that is being hosted in a WinForm window.  The save button is not in my view but it's in the winform window.  When user type in the xamDataGrid text cell and click on the save button, the xamGrid is not getting the KillFocus event and therefore the source is not getting updated.  I tried the following workaround but its not clean and not working quite right. I'm using Infragistics WPF controls v14.1

1. I created a TextEditor style with XamTextEditor and set the dirtyFlag on my viewModel OnTextChanged like so.  I can't update the source OnTextChanged because it will trigger premature validation.

<Style TargetType="{x:Type dge:XamTextEditor}" x:Key="GridTextBoxStyle">
   <Setter Property="EditTemplate">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type dge:XamTextEditor}">
            <TextBox Name ="txtFieldValue" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextChanged="FieldValue_TextChanged" />
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>

<igWPF:XamDataGrid x:Name="IgDataGrid"
   DataSource="{Binding TimeCollection}"
   SelectedDataItemsScope="RecordsOnly"
   ActiveDataItem="{Binding SelectedTime}"
   EditModeStarted="DataGrid_EditModeStarted">
   <igWPF:XamDataGrid.FieldLayouts>
      <igWPF:FieldLayoutKey="TimeColumns">
         <igWPF:FieldLayout.Fields>
            <igWPF:Field Name="StartTime" Width="Auto" >
               <igWPF:Field.Settings>
                  <igWPF:FieldSettings
                     EditorStyle="{StaticResource GridTextBoxStyle}"
                     EditorType="{x:Type dge:XamTextEditor}"
                     EditAsType="{x:Type sys:String}" />
                 </igWPF:Field.Settings>
              </igWPF:Field>
              <igWPF:Field Name="Group" Width="Auto">
                 <igWPF:Field.Settings>
                    <igWPF:FieldSettings
                       EditorStyle="{StaticResource GridTextBoxStyle}"
                       EditorType="{x:Type dge:XamTextEditor}"
                       EditAsType="{x:Type sys:String}" />
                    </igWPF:Field.Settings>
                 </igWPF:Field>
              </igWPF:FieldLayout>
           </igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>

3. I also saved the LastActiveField OnEditModeStarted event so I can update the source manually when Save button is clicked:

private void DataGrid_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
   MyViewModel vm = ViewModelLocator.GetInstance().MyViewModel;
   if (vm != null)
   {
      vm.LastActiveField = e.Cell;
      vm.LastEditor = e.Editor;
   }
}

3. When user Click Save button and if dirtyFlag is true it updates the source manually like so:

protected void UpdateLastField()
{
  MyViewModel vm = ViewModelLocator.GetInstance().MyViewModel;
  if (vm != null && vm.LastActiveField != null)
  {
      if (vm.LastEditor != null)
      {
         if (vm.LastActiveField is Infragistics.Windows.DataPresenter.Cell)
         {
            var cell = (Infragistics.Windows.DataPresenter.Cell)vm.LastActiveField;
            ValueEditor editor = vm.LastEditor as ValueEditor;
            if (editor is XamTextEditor)
            {
               cell.Value = editor.Text;
            }
            editor.EndEditMode(true, true);
         }
      }
   }
}

This whole thing feels like a hack and also when I tab from cell to cell I want the next cell to be in edit mode but it's not.

 The cell in focused just have the dashed line around it.

 A better solution is very much appreciated.

Parents Reply Children
No Data