C1FlexGrid width

2019-07-09 14:04发布

I started using ComponentOne's C1FlexGrid for my WPF Caliburn.Micro application. I wonder how I can set with of the columns to the maximum contents width. I tried to make it Auto, but the width is still the same for all columns.

I applied AutoSizeColumns like this:

      protected override void OnViewAttached(object view, object context)
  {
      var View = (FirstDataEntryView)view;
      View.EnrollmentFiles.AutoSizeColumns(0, 4, 5);
  }

but this didn't help...

Thanks

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-09 14:41

Using GridLength.Auto usually doesn't work for these column widths because of virtualization. FlexGrid has a couple methods to autosize the columns but the columns must be visible or they won't be calculated and will remain the static width. Here is a very non-production-worthy example of how to do this. FWIW this is why I never liked ComponentOne controls -- it felt like they were stuck in WinForms mode.

edit: Adding some code for CM-specific usages.

protected override void OnViewAttached(object view, object context) {
    View = (YourViewType)view;
    View.flexGrid.AutoSizeColumns(0,4,5);
}

As far as whether or not accessing the view from a viewmodel is "compliant" with MVVM theories -- technically it is not, but sometimes you are forced to use controls that just cannot be automatically configured through XAML, and you can't use the View's code-behind because of one reason or another.

查看更多
登录 后发表回答