I have retemplated the GroupByRecordPresenter with no problem. I have custom text and buttons that show up.
What I would like to have happen is that items in a certain column are hidden when they are grouped.
This is the field I'm trying to change:
<igDp:Field Name="Instrument" Label="{Resx ResxName=Gui.Resource, Key=GuiInstrument}" Width="*"> <igDp:Field.Settings> <igDp:FieldSettings AllowHiding="Never" CellValuePresenterStyle="{StaticResource InstrumentVisible}"/> igDp:Field.Settings> igDp:Field>
This is the CellValuePresenterStyle I'm using:
<Style TargetType="{x:Type igDp:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDp:CellValuePresenter}}" x:Key="InstrumentVisible" x:Shared="False"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record, Converter={StaticResource GroupedInstrumentConverter}}" Value="True"> <Setter Property="Visibility" Value="Hidden"/> DataTrigger> Style.Triggers> Style>
And this is the converter I'm using:
public class GroupedInstrumentConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is Record) { Record r = value as Record; if (r.FieldLayout.Fields["StrategyString"].IsGroupBy) return true; else return false; } // value wasn't valid, return nothing return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Not used, return nothing return null; } }
The code does go through the converter just fine, but the visibility of the cell is still Visible, when I want it to be Hidden. Any tips for what I'm doing wrong?
Hi Dierk,
I am glad that I was able to assist you.
If you have any other questions or concerns, please do not hesitate to ask!
Thanks,
Stefana
This put me on the right track. I needed this on a per cell basis, not the whole field, and I actually had 2 conditions to check, so here's what I did.
Here is the CellValuePresenterStyle:
<Style TargetType="{x:Type igDp:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDp:CellValuePresenter}}" x:Key="InstrumentVisible" x:Shared="False"> <Style.Triggers> <DataTrigger Binding="{Binding Source={StaticResource VisViewModel}, Path=isGrouped, Converter={StaticResource GroupedInstrumentConverter}, Mode=TwoWay}" Value="True"> <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.StrategyString, Converter={StaticResource GroupedInstrumentConverter}}"/> DataTrigger> Style.Triggers> Style>
The field:
And the converter:
public class GroupedInstrumentConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (targetType == typeof(Visibility)) { if (!string.IsNullOrEmpty(value.ToString())) return Visibility.Hidden; else return Visibility.Visible; } else { return (bool)value; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Not used, return nothing return null; } }
These were used in conjunction with the view model and field property changed events in your sample project. Thanks for the help.
Hi,
Thanks for the feedback provided.
I would offer an alternative solution to your problem - see the attached sample.
Thanks for your response. The reason I was using a DataTrigger is because I want the Visibility of the Instrument column to based on the IsGroupBy of the StrategyString column. What you suggested would work if I was grouping on the Instrument column, but that's not the case.
If I understand you issue correctly, I would suggest the following solution:
1. Binding directly the Field Visibility property to the IsGroupBy property (no style is necessary), while using converter:
<igDP:Field Name="Instrument"
Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsGroupBy, Converter={StaticResourceGroupedInstrumentConverter}}">
</igDP:Field>
2. Change the converter to do the following:
public class GroupedInstrumentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
if (targetType == typeof(Visibility))
return (bool)value ? Visibility.Collapsed : Visibility.Visible;
}
else
return (bool)value;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return null;
Let me know in case you need further assistance!