I am trying to add an UnboundField using a Style to add a button.
All works well when I have the ShouldCollapseEmptyCells set to false but when I try to set this to true it does as expected with the empty fields with the exception of the unbound field using the button style.
I have tried giving the field a value I have tried to set the field visibility but nothing works when set to true. How can I solve this issue?
The other issue has to do with how to set each individual datacards cell properties when I try to set a background color it sets it for all cards.
Thanks
Hello,
I was not able to reproduce this issue. I am attaching the sample project that I used to reproduce this. Please let me know if you are able to reproduce it or modify it so that the issue is reproducible.
Guess I made a mistake it is not a button that I am trying to put into the unbound field but a stackpanel with an Image and a label.
The included project demonstrates the collapsed field issue and also shows the issue with trying to update a single card view to show a different background color (change is instead made for all card views).
I apologize for the delayed response. I ran the project and everything worked correctly with no exceptions.
The only thing that I notice is a binding expression errors in the output window. What environment are you testing this under?
So when you run the project only 'Item 1' is highlighted? And you see the Image and label ("Review")?
I am working with VS 2010 on Vista 32 bit.
Here is a screenshot of what I am seeing (no exceptions)
If you want to collapse the space for that field, you can set the CellContentAlignment to ValueOnly, which will remove the LabelPresenter for that field and leave only the CellValuePresenter. This would work for the XamDataGrid as shown in this thread here. However, the XamDataCards uses a different layout and you will probably have to set the CellHeight as well.
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="ReviewButtonStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel Orientation="Horizontal" Height="40"> <Image HorizontalAlignment="Left" Width="20" Height="20" MouseLeftButtonDown="Image_MouseLeftButtonDown" Source="/InfragisticsProblem;component/Images/Book_openHS.png" /> <Label MouseLeftButtonDown="Image_MouseLeftButtonDown" >Review</Label> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="False"> <Setter Property="Visibility" Value="Hidden" /> </DataTrigger> <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="True"> <Setter Property="Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style>
The solution works for the background but I am still having issues with the unbound field.
How can I actually collapse the field?
When the item is hidden it shows a blank field which I would like to get rid of and Collapse does not actually collapse the field.
Thanks,
Thank you for clearing this out.
Even though you are checking for the cell's value in the InitializeRecord event of the XamDataGrid, you are still assigning this style to the whole field. This means that all cells inside that field will pick it up. What you need to do is conditional formatting based on its value. You can use this style :
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="TestBackColor">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Value, RelativeSource={RelativeSource Self}}" Value="Item 1">
<Setter Property="Background" Value="MistyRose" />
</DataTrigger>
</Style.Triggers>
</Style>
to change the background of a particular cell with a specific value. However, a better approach will be to use IValueConverters. You can see how here.
Regarding the unbound field, the XamDataCars considers this an empty cell, because it is not bound to anytihng - therefore it is empty. If you set the BindingPath of the unbound field to some field of your data source, it will no longer be empty (despite retemplating its CVP) and will be displayed.
For this, all you need to do is to change the setter to :
<Setter Property="Visibility" Value="Hidden"/>
and bind it to some field as discussed. The result : this cell will be visible when moues over.
Well there's the problem. Notice that all of the Name fields have a different background than the rest? What is intended here is that only the one named Item 1 should be highlighted. If you look at the code I am trying to set the background for only 'Item 1' but instead it is set for all card views. Am I going about this the wrong way? (works on grid).
The second issue is the missing Unbound Test field which should be visible but is not when the 'ShouldColapseEmptyCells' is set to True. What I am looking to do is to show the Unbound field only for certain situations.
This is sort of what I want when 'ShouldCollapseEmptyCells' is true. Except that I would like to be able to control when the Unbound field is displayed per card.
Thanks for the quick response.