Trouble with AutoSizeRows on Bound Wrapping for FlexGrid

Posted by: lmclean on 21 September 2017, 10:00 pm EST

  • Posted 21 September 2017, 10:00 pm EST

    I'm having an issue with the C1FlexGrid.AutoSizeRows method on a specific column.

    We have a C1FlexGrid as defined below:
    <c1:C1FlexGrid x:Name="FlexGrid" Style="{StaticResource FlexGridStyle}" ItemsSourceChanged="FlexGrid_OnItemsSourceChanged> <!-- ItemsSource set in code behind upon certain events elsewhere in control -->
    <!-- Other columns that aren't causing issues -->
    <c1:Column Binding="{Binding Notes}" Header="Notes" Width="*" MaxWidth="600" HeaderHorizontalAlignment="Center">
    <Style TargetType="TextBlock" BasedOn="{StaticResource customTextBlockStyle}">
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TheUserControl}, Path=DataContext.Settings.NotesWrapping}" Value="False">
    <Setter Property="ToolTip" Value="{Binding Notes}"/>
    <Setter Property="TextTrimming" Value="WordEllipsis"/>
    <Setter Property="Text" Value="{Binding Notes, Converter={StaticResource stripMultiLineUseEllipsisConv}}"/>
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TheUserControl}, Path=DataContext.Settings.NotesWrapping}" Value="True">
    <Setter Property="Text" Value="{Binding Notes}"/>
    <Setter Property="TextTrimming" Value="None"/>
    <Setter Property="TextWrapping" Value="Wrap"/>


    private void FlexGrid_OnItemsSourceChanged(object sender, EventArgs e)
    var timer = new Timer(1000){ AutoReset = false };
    timer.Elapsed += (o, args) => { Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (Action)delegate { FlexGrid.AutoSizeRows(0, FlexGrid.Rows.Count - 1, 0, true); }); };

    Essentially, we have a setting as to whether the notes column should wrap or not. If it wraps, it should be completely visible and not have a tooltip. If it's not wrapping, it should have a tooltip displaying the whole contents, and trim the text to put an ellipsis if too long or if more than one line. The StripMultiLineUseEllipsisConv handles the multi-line text trimming.

    Unfortunately, the AutoSizeRows method doesn't seem to work when we use a DataTrigger binding on the textblock. It will only size to the height of one line regardless of whether the wrapping is on or off. The method does work if we manually set in the xaml on the TextBlock the TextWrapping property to Wrap or NoWrap as appropriate.

    Interestingly, if the "extra" parameter (third in the AutoSizeRows method) is set to something like 50 or 100, the rows do resize properly with the text wrapping, with the additional 50/100.

    Any suggestions on how I can work around this to get the desired behaviour, with extra being 0?

    Our version for C1.WPF.FlexGrid.4 is 4.0.20142.409.
  • Replied 22 September 2017, 2:05 am EST

    We found a non-ideal work-around: We set the extra to be 25 (which suffices to force it to be proper height plus 25), then set again to 0 in the same timer elapsed event. It results in some flashing but is functional.
  • Replied 22 September 2017, 9:50 am EST


    Could you please share your application or stripped version of your application, so that we could share a resolution to your issue that works precisely with your application.

    Ruchir Agarwal
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels