Hey,
We need little assistance on this one. All our fields/columns are loading various styles depending on the type of data. All styles are working fine in their individual Cell. Now we have a situation where we would like to set the background color of the entire record based on a field and the individual cell should continue displaying their corresponding style.
Example:
My datagrid contains 4 fields/Columns named Play, Stop, Queue, Name. Correspnding to each field we have specified a CellValuePresenter style which loads images. This is all working. Now based on specific Queue field we need to highlight or set the background color of the entire record. This can't be CellValuePresenter Style as this would overwrite our previous styles for individual cells. DataRecordPresenter style may be the option But couldn't get that one working. We want to do this in xaml and not in code.
How do we deal with such a situation.
Thanks
Ferhaad
Hi,
I have to apply different style for a cell based on a condition for e.g. if my data type is image I have to display a button using cellvaluepresenter for browsing, else nothing should be their for that cell. Problem is last style which I assgined on the cell same style gets applied for the entire column.
If currentRecord.Cells("DisplayType").Value = "Image" Or currentRecord.Cells("DisplayType").Value = "System.Binary" Then
currentRecord.Cells("ImageFile").Field.Settings.CellValuePresenterStyle = DirectCast(FindResource("ButtonPresenterStyle"), Style)
currentRecord.FieldLayout.Fields("ImageFile").Settings.CellValuePresenterStyle = DirectCast(FindResource("ButtonPresenterStyle"), Style)
Else
currentRecord.Cells("ImageFile").Field.Settings.CellValuePresenterStyle = DirectCast(FindResource("NoButtonPresenterStyle"), Style)
currentRecord.FieldLayout.Fields("ImageFile").Settings.CellValuePresenterStyle = DirectCast(FindResource("NoButtonPresenterStyle"), Style)
End If
<Style x:Key="ButtonPresenterStyle"
TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Canvas>
<Button x:Name="btnControlButton"
Margin="2"
Click="btnControlButton_Click"
Content="...">
</Button>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NoButtonPresenterStyle"
<Label>NoButton</Label>
</Window.Resources>
Any reason like where I am going wrong or whether it is possible
Hi there,
Most of the time we been applying style in the xaml using datatriggers. Below is the sample code to give you an idea how things work..Need to make sure that your binding is correct so that your trigger gets executed.
ferhaad
<Style x:Key="CustomPresenter" TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Resources> <ControlTemplate x:Key="ButtonPresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Canvas> <Button x:Name="btnControlButton" Margin="2" Click="btnControlButton_Click" Content="..."> </Button> </Canvas> </ControlTemplate> <ControlTemplate x:Key="NoButtonPresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Label>NoButton</Label> </ControlTemplate> </Style.Resources> <Style.Triggers> <Setter Property="Template" Value="{StaticResource NoButtonPresenterStyle}" /> <DataTrigger Binding="{Binding Path=Record.DataItem.DisplayType, RelativeSource={RelativeSource Self}}" Value="Image"> <Setter Property="Template" Value="{StaticResource ButtonPresenterStyle}" /> </DataTrigger> <DataTrigger Binding="{Binding Path=Record.DataItem.DisplayType, RelativeSource={RelativeSource Self}}" Value="System.Binary"> <Setter Property="Template" Value="{StaticResource ButtonPresenterStyle}" /> </DataTrigger> </Style.Triggers> </Style>