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
55
Setting AllowEdit to false on cells using XamNumericEditor template
posted

Hi,

I am using XamDataGrid and I have a number of UnboundFields that have to be initialised in the code-behind.

Each of the cell in these columns binds to an instance of an object which has the following properties.

- Vol: the double value to display in the cell

- IsMin: bool

- IsMax: bool

I don't want these cell to be editable so i've set field.Settings.AllowEdit = false but it still allows the user to edit it.

I think this is because I use a control template on these cells of type XamNumericEditor to highlight the cells that IsMin or IsMax.

Is there anyway to prevent users from editing this cells?

------------------------------------------------------------------------------------------------------------

The style I defined as is follows:

<Style x:Key="ExpiryEditorStyle" TargetType="{x:Type Editors:XamNumericEditor}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Editors:XamNumericEditor}">
<Editors:XamNumericEditor Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
FontWeight="{TemplateBinding FontWeight}"
BorderThickness="0"
Value="{Binding RelativeSource={RelativeSource AncestorType=igDP:CellValuePresenter}, Path=Value.Vol}" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=igDP:CellValuePresenter}, Path=Value.IsMax}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.ShowHeatMap}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
</MultiDataTrigger>

<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=igDP:CellValuePresenter}, Path=Value.IsMin}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.ShowHeatMap}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
------------------------------------------------------------------------------------------------------------

[NB] I had to use XamNumericEditor as template because when I tired using CellValuePresenter, the binding failed and nothing was displayed.

Also, the reason IsMin is a property of the object I bind to is because Min is not the smallest value in the field.

It is dependent on other properties within the row. The same applies to IsMax

Thank you