Hi,
I have DataRecords with property, which "knows" if it should be editable for the user or not. Something like:
public class StringProperty
{
public string StringValue { get; set; }
public bool AllowEdit { get; private set; }
}
So I create a Field with Binding to the StringProperty property and a Template to display it and it works so far. But how can I bind the AllowEdit property of each cell (or CellValuePresenter) to the AllowEdit property of the data? (The AllowEdit is set by the business logic according some rules, such as expiration date, etc...).
Thanks in advance,
George
HI George,
I am attaching a sample that may help you resovle your issue.
Sincerely,
Matt
Developer Support Engineer
Hi Matt,
this works fine. But it uses the IsEnabled Property of the CellValuePresenter. Because of the look and feel, I would like to use the IsEditingAllowed, which is unfortunately a ReadOnly property. Can you tell me, what sets the IsEditingAllowed property? How can I control it?
Best Regards,
Hello Rajib,
Thank you for your post. I have been looking into it and I can suggest you use the Field's AllowEdit Proeprty instead of IsEditable one in order to be able to show ToolTips on non-editable Cells. You can also use the Editor's IsReadOnly Property, which doesn't block the tooltip neither.
In my scenario, I also need to make the entire row disabled, but the problem is I need to show Tooltip on each cell(editable or non-editable). The Tooltip gets disabled when IsEnabled = false. How to show the tooltip on a disabled cell ?
I gradually found some solution, which will be satisfactory for now. (see my previous post)
Thank you very much for your guidance.
You could use the EDitModeStarting Event and cancel it.
I think the best soltuion was the first one I provided, It used the IsEnabled Property of the CellValuePresenter.
This prevented going into edit mode and it also styled the row so that the enduser will know its readonly.
You want the enduser to know which rows are editable.
Matt Developer Support Engineer
I found a solution/work around for this. If you have custom EditorStyle, you can set the Template (which is only for viewing) directly and set the EditTemplate through a DataTrigger. In this case the EditTemplate will be defined only if the trigger is satisfied. In this way you can control each cell individually directly from the ViewModel. Here is a Snippet for the easiest case - StringValue:
<Style x:Key="CustomStringEditorStyle" TargetType="{x:Type local:CustomValueEditor}"> <Style.Triggers> <DataTrigger Value="True"> <DataTrigger.Binding> <Binding RelativeSource="{RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}" Path="Value.AllowEdit" /> </DataTrigger.Binding> <Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch"> <TextBox Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value.StringValue, Mode=TwoWay}" Height="23"> </TextBox> </Grid> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch"> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value.StringValue}" Height="23" TextTrimming="CharacterEllipsis"> </TextBlock> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
Once you have the Style you can set it to the Field.Settings.EditorStyle directly or use the Field.SettingsEditorStyleSelector instead. This worked for me, hope someone else could also benefit.
Regards,