Hi,
I display and edit a bunch of custom objects in the XamDataGrid. For this purpose I have my own Editor and EditorStyles. Here is one example:
<Style x:Key="PropertyValueStringEditorStyle" TargetType="{x:Type editor:IPropertyValueEditor}"> <Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch"> <TextBox Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value, Converter={StaticResource pvsc}, Mode=TwoWay}" Height="23"> </TextBox> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch"> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value.ToStringProperty}" Height="23" TextTrimming="CharacterEllipsis"> </TextBlock> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
As you can see, the Style has as well Template as EditTemplate Setter.
If I set the Field.Settings.EditorStyle directly, it works! But if I set the Field.Settings.EditorStyleSelector the cells are not editable. Here is the Implementation of the StyleSelector:
public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container) { if (container != null) { var cvp = container as CellValuePresenter; Type t = cvp.Field.DataType; if (t == typeof(PropertyValueString)) { return cvp.TryFindResource("PropertyValueStringEditorStyle") as Style; } ... } return base.SelectStyle(item, container); } }
The method returns the right style so the problem is not there, but the CellValuePresenter.IsEditingAllowed remains always False. The Template is set correctly, but the EditTemplate is not (I suppose.)
Any help will be appreciated!
Regards
George
Hi Rob,
Thank you for the quick answer.
Your sample works on my side. And the weird thing is, that in my project I have the same implementation, but still doesn't go in edit mode.
I will look for differences and if I don't find any I will contact you again on this issue. Otherwise I will mark the topic as aswerd.
Regards,
Hi George,
What is IPropertyValueEditor? Is that your own custom ValueEditor object?
I've created a sample using your style and the EditorStyleSelector seems to be able to use the style properly for the column it's applied to. I'm able to view and edit the data for each cell in that column. I've attached my sample for your consideration.
I'm not sure what else you might have in your application but can you download and run my sample to see if it works on your end?