Hi,
I have a xamDataGrid, and for one particular cell I want to have one EditorStyle based on a boolean value from the data object being bound for that row. Any ideas?
You can absolutely do that. In fact, there's a lot of examples in this forum on how to achieve that using a style. Here is an example that I just posted for another question. It shows a boolean value being used to set the background color of a cell.
<Window x:Class="XamDataGrid_Test_of_Dynamic_Style.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:local="XamDataGrid_Test_of_Dynamic_Style" Title="Window1" Height="300" Width="300"> <Grid> <Grid.Resources> <Style x:Key="ManagerStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=(igDP:DataRecord.DataItem).IsManager}" Value="True"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Style> </Grid.Resources>
<StackPanel Orientation="Vertical">
<Button Name="ToggleManager" Click="ToggleManager_Click" Margin="20">Toggle Manager</Button>
<igDP:XamDataGrid Name="TestGrid" AutoFit="True" GroupByAreaLocation="None">
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout>
<igDP:FieldLayout.Fields> <igDP:Field Name="Name"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource ManagerStyle}" /> </igDP:Field.Settings> </igDP:Field>
<igDP:Field Name="IsManager" /> </igDP:FieldLayout.Fields>
<igDP:FieldLayout.SortedFields> <igDP:FieldSortDescription FieldName="Name" Direction="Ascending" IsGroupBy="False" /> </igDP:FieldLayout.SortedFields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</StackPanel>
</Grid></Window>
My mistake... I wanted to change EditorType per row. Actually, I don't even need to do that... just disabling the editor control per row would be fine for me. I can't seem to find a way to do this... either all rows get the AllowEdit (or other settings), or none of them do.
I found a way to do this in code though, by handling EditModeStarting and setting e.Cancel approperiately.