Hi guys!
Does anyone know how to set the Visibility of a record in the XamDataGrid using data binding?
What I want to do is bind a collection of objects to the grid, and using a property on the object to determine if the record should be visible or collapsed.I have tried creating a style for the DataRecordPresenter where I set the Visibility using data binding like this;
DataSource="{Binding Path=ImportData}">
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
Value="{Binding Path=DataItem.ExistsAtTarget, Converter={StaticResource visibilityValueConverter}}"/>
</Style>
</igDP:XamDataGrid.Resources>
I have verified that the data binding actually occurs for each item (by setting a break point in the ValueConverter), but when the grid is rendered, every record is visible even if they shouldn't be...
Any ideas? Am I doing this all wrong?I know I can do this in code, but I would like to do it in XAML if it's possible...
Thanks!
You're most welcome! Mole is infinitely useful. I literally use it every day. :)
But, don't just thank me. Also thank Andrew Smith (of Infragistics) and Karl Shifflett (of Microsoft). I was just one guy on the team.
Ok, thanks!
I think I'll go with the filtering option for now.And by the way, thank you for Mole...it's a brilliant tool!...if I could I would have nominated you (and your partners) for a "Nobel Programmer Prize" or something like that..my war with the visual tree has calmed:)
Hi,
I checked this out in Mole. It seems that the Visibility of the DataRecordPresenter is set to 'Visible' as a "local" value, meaning that value will take precendence over a value supplied by Setters/Styles/Triggers/etc. I'm not sure if that is a bug or not, but it certainly will block you from being able to filter out the rows using the XAML-only approach you've described. You can bring this up with our Developer Support group and see what the Engineering team can do about it. In the meanwhile, you'll need to write code to hide the records. Or, you can bind the grid to a filtered list of objects, so that hiding them is not necessary at all.
Josh
public class BooleanToVisibilityValueConverter : IValueConverter
{
#region IValueConverter Members
}
else
#endregion
Also, I tried setting the record visibility in the XamDataGrid.InitializeRecrod event handler, but that crashed by entire application...(at least when all my records were set to Collapsed)
I've never tried setting rows to be collapsed. Assuming it's possible (although I'd think you'd want to filter the data source), could you post the converter code for review?