Is there any way I can display the text in a particular cell with Bold text based on the value of another cell in the same row ? I.e I have a IsDefault cell and if this is set tro 1 I would like another cell to be displayed with different formatting.
Many Thanks
Niclas
Hello Niclas,
Yes, it is possible. You should create a style for the CellValuePresenter and use DataTrigger for the Value property of the cell that you want to access. You should set the Path to Cells[namecell"].Value and then use a Setter for the FontWeight property.
Please let me know if you need further assistance with this. It should look something like this:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[IsDefault].Value}" Value="1">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
Could this be done in code behind (which im for familiar with than XAML)
Thanks
Niclas,
This should be the c# equivallent:
Style s = new Style(typeof(CellValuePresenter));
DataTrigger trigger = new DataTrigger();
Binding binding = new Binding("Cells[IsDefault].Value");
trigger.Value = "1";
trigger.Binding = binding;
Setter setter = new Setter(CellValuePresenter.FontWeightProperty, FontWeights.Bold);
trigger.Setters.Add(setter);
Thanks,
Assume I should run this at the time of binding of the Grid, but having looked at the events available there does not seem to be an event for this. Where should I execute this code ?
Thanks for your help
As this is a style, you just have to add it in the Resource dictionary of the XamDataGrid. You can do this in any event - for example - in the FieldLayoutInitialized, when the FieldLayout is created (right after you bind the XamDataGrid) or in the Loaded event of the XamDataGrid.
Hi Alex. I have tried all I know this afternoon. It looks ok to me. There is a field in the datasource "CareUnit" I have made sure its trimmed. It can either be "ICU" or "HDU" - please if you have any ideas I'd be stoked! Thanks
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="UserImage1"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Grid Width="50" Height="50"> <Image x:Name="myImage" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Source="{DynamicResource BuddyYellow}"> </Image> </Grid> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding Path=Record.DataItem.CareUnit}" Value="ICU" > <Setter TargetName="myImage" Property="Image.Source" Value="{DynamicResource BuddyBlue}"/> </DataTrigger> <DataTrigger Binding="{Binding Path=Record.DataItem.CareUnit}" Value="HDU" > <Setter TargetName="myImage" Property="Image.Source" Value="{DynamicResource BuddyBlue}"/> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Hi Alex
Could you please help me with the syntax? I have been having trouble. This is the CVP style
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="UserImage1">
="Template">
>
}">
="50">
="BuddyImage"
}"
}"/>
Thank you I will give this a shot tomorrow
If you have only couple of scenario when you want to change the image, then it would be better to use triggers than IValueConverter. What you can do is to create a DataTrigger or a Trigger inside the control template of the CVP. It will bind to the CVP's Value property or the Record.DataItem.PropertyName and based on the value (1,2,3,4) create a setter that changes the Source property of the Image.
The example is attached to this post test.zip. What I need to do is based on a value in a cell, for example a status (1,2,3,4) or (Complete, Failed, Processing) display a different image based on this value in an unbound field.
For example if Complete, the image would be a tick icon, failed and cross icon type thing. I have done this a lot in .NET by calling a function when the field is bound to select the correct image source based on a cells value.
Hope that makes sense? I am using 9.1