Converters are called every time a key is pressed, and not at the end of user input

I had a problem with data entry from the moment of transition to .NET 4.0. In my Xceed 3.7 grid, the user was able to enter a value in the cell, and when he pressed or pressed the enter button, the method of the associated ConvertBack converter is ConvertBack , analyzing the input value of the user and saving in the desired format.

Now everything is unexpected, this happens every keystroke - which causes a huge problem, because if the user erases the number and starts to enter another one (say, -100), as soon as they dial a negative sign, the callback is triggered and throws an exception because "-" is not a syntax string, and the value is returned.

I think the problem is pretty clear, so now I will embed the code.

The user input columns are as follows:

 <xcdg:DataGridControl x:Name="AggCatGrid01" ItemsSource="{Binding Source={StaticResource myDataSource}}" > <xcdg:DataGridControl.Columns> ... <xcdg:Column VisiblePosition="0" FieldName="SomeValue" Title="Some Value" CellEditor="{StaticResource PercentageEditor}" CellContentTemplate="{StaticResource EditablePercent2CellContentTemplate}" /> 

Datagrids have a common style:

 <Style x:Key="{x:Type xcdg:DataGridControl}" TargetType="{x:Type xcdg:DataGridControl}"> <Setter Property="UpdateSourceTrigger" Value="CellEndingEdit"/> <Setter Property="AutoCreateColumns" Value="False"/> <Setter Property="EditTriggers" Value="BeginEditCommand, CellIsCurrent, ActivationGesture"/> <Setter Property="CellEditorDisplayConditions" Value="CellIsCurrent"/> <Setter Property="NavigationBehavior" Value="CellOnly"/> 

Note that the UpdateSourceTrigger parameter UpdateSourceTrigger set to CellEndingEdit . I would think that right here would be responsible for when the converters are called and the associated value is updated. No matter what changes have changed, just by switching .NET4.

Here is the data pattern for the column that you saw above:

 <!-- Styles used when editable cells are being edited. --> <xcdg:CellEditor x:Key="PercentageEditor"> <xcdg:CellEditor.EditTemplate> <DataTemplate> <xcdg:AutoSelectTextBox Style="{StaticResource DefaultAutoSelectTextBox}" Text="{xcdg:CellEditorBinding Converter={StaticResource EditablePercentageConverter}}" /> </DataTemplate> </xcdg:CellEditor.EditTemplate> </xcdg:CellEditor> 

I think the converter code itself does not matter, so I will leave it without a request. The problem is that it gets a call every time a key is pressed.

If you can shed light on this, I will be delighted. I mean, I might have to roll back all my .NET 4.0 enhancements or delay my next release for more than a month, rewriting all my datagrids so that I no longer have to use xceed if there is no solution for this. Thanks guys.


Update # 1

I really came up with a moderately smart solution (in my humble opinion) where I present a dummy text block to hold CellEditorBinding xceed makes us use in a datatemplate. Then I changed my input control to directly associate it with the text property textblock, and not with CellEditorBinding, which allowed me to specify my own binding mode. Here I managed to set the "lostFocus" mode, and the main problem was solved! The converter is no longer called on every keystroke, but only when the user leaves the cell or gets into it.

 <xcdg:CellEditor x:Key="PercentageEditor"> <xcdg:CellEditor.EditTemplate> <DataTemplate> <Grid> <TextBlock x:Name="bind_source" Text="{xcdg:CellEditorBinding}" Visibility="Collapsed"/> <xcdg:AutoSelectTextBox Style="{StaticResource DefaultAutoSelectTextBox}" Text="{Binding ElementName=bind_source, Path=Text, Mode=TwoWay, UpdateSourceTrigger=LostFocus, Converter={StaticResource EditablePercentageConverter}}" /> </Grid> </DataTemplate> </xcdg:CellEditor.EditTemplate> </xcdg:CellEditor> 

As you can imagine, this layer of indirection causes several other minor issues, such as violation of the test. Oddly enough, now that the user enters invalid data, the converter throws an exception that xceed catches and uses to include the cell error pattern, but fixing the error and pressing input no longer works. Only the user option is to press the ESC key, as a result of which the cell value will return and lose focus before they can correct their record.

User must hit ESC in this situation to continue editing cells. Simply clicking away or changing the value back to something valid doesn’t work.

I still hope for a more elegant solution that will fix this.


Update # 2

I found a developer on the Xceed support forums that presented the same problem as me in this post: http://silverlightdatagrid.com/CS/forums/permalink/31548/31516/ShowThread.aspx#31516 .

Many users seem completely confused by your examples (which are pretty much outdated .Net 4.0) and focus only on their own controls using xcdg: CellEditorBinding, which seems to support PropertyChanged validation .

Unfortunately, a solution has never been proposed. He presented a strategy to change the trigger of the update source more elegantly, which I could accept, but I still have a problem with a cell-specific validation error until the user presses ESC.

 <xcdg:AutoSelectTextBox Style="{StaticResource DefaultAutoSelectTextBox}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=xcdg:DataCell}, Path=Content, UpdateSourceTrigger=LostFocus, Converter={StaticResource EditablePercentageConverter}}" /> 

Update # 3

I confirmed that by updating Xceed DataGrid version 4.3 (in the trial version), the problem disappeared on its own, since in this version Xceed updated his xcdg:CellEditorBinding UpdateSourceTrigger incompatible with .Net4. 0. Since, however, the Xceed license only includes 6 months of bug fixes before you have to pay for a completely new license (ridiculous), and I don’t see any company allowing an outrageous license fee for a single $ 1,200 for using the latest Xceed dll just for this minor bug, I'm still going to find a complete workaround in Xceed version 3.7. I will introduce this “solution” for developers who have access to write money.

As it turned out, updating to 4.3 did not solve the problem. It just appeared because I forgot to undo my previous change. Even in the latest version, Xceed has not yet set the UpdateSourceTrigger property to CellEditorBinding .

+6
source share
2 answers

Decision:

 <xcdg:AutoSelectTextBox Style="{StaticResource DefaultAutoSelectTextBox}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=xcdg:DataCell}, Path=Content, UpdateSourceTrigger=LostFocus, Converter={StaticResource EditablePercentageConverter}}" /> 

There really is no other way to do this. If you are not using the latest version of Xceed, this will also lead to validation errors, but using the new binding path in the latest version works fine. I still consider this a hack, and I hope you understand that he needs to set a few more properties on CellEditorBinding .

+3
source

I do not know the XCeed controls, so this is just a reasonable assumption.

I personally posted the UpdateSourceTrigger in the binding declaration, as is done in normal .NET management:

 Text="{xcdg:CellEditorBinding Converter={StaticResource EditablePercentageConverter}, UpdateSourceTrigger=CellEndingEdit}" 

In addition, since the management is commercial, you must be entitled to some technical support from XCeed.

0
source

Source: https://habr.com/ru/post/906867/


All Articles