public class ExpansionVisibilityConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((value as DataRecordPresenter).IsHeaderRecord || !isContainChildRecordCountCell(((value as DataRecordPresenter).Record as DataRecord)) || ((value as DataRecordPresenter).Record as DataRecord).Cells["ChildRecordCount"].Value == null || ((value as DataRecordPresenter).Record as DataRecord).Cells["ChildRecordCount"].Value.ToString() == "0") { return Visibility.Hidden; } return Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return Binding.DoNothing; } private bool isContainChildRecordCountCell(DataRecord dr) { foreach (Field field in dr.FieldLayout.Fields) { if (field.Label.ToString().Equals("ChildRecordCount", StringComparison.InvariantCultureIgnoreCase)) return true; } return false; } #endregion }