I have a grid where some cells contain text that is too long. When I autosize the columns, the columns can become too wide for the user (over 3000px). I'd like to implement a simple condition where I have a maximum column width, but only when autosizing. I'd still like the user to be able to size the column. However, when I tried to set the width after the resize operation, things didn't quite work out.
I wrote a very simple app to illustrate my point:
<Window x:Class="AutoSizeApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ig="http://infragistics.com/DataPresenter" Title="MainWindow" Height="350" Width="525"> <StackPanel Orientation="Vertical"> <Button Click="Button_Click">Auto Resize</Button> <ig:XamDataPresenter x:Name="grid" BindToSampleData="True"> </ig:XamDataPresenter> </StackPanel></Window>
using System.Windows;using Infragistics.Windows.DataPresenter;
namespace AutoSizeApp{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }
private void Button_Click(object sender, RoutedEventArgs e) { foreach (var field in grid.DefaultFieldLayout.Fields) { field.PerformAutoSize();
// Works only the first time around. double max = 10; if (field.CellWidthResolved > max) { field.Settings.Width = new FieldLength(max); } } } }}
When I click the Auto Resize button, the first time around the cells will resize, but the max width will be at 10px, as the code intended. When the button is clicked a second time, and any subsequent time after that, the 10px setting is completely ignored, and the autosize resizes to the text regardless of how long it is.
How can I cap the width of the columns after a PerformAutoSize() call?
Hello,
After some research Autosize with Min/Max has been determine as a new Product Idea. I have sent your Product Idea directly to our product management team. Our product team chooses new Product Ideas for development based on popular feedback from our customer base. Infragistics continues to monitor application development for all of our products, so as trends appear in requested ideas, we can plan accordingly.
We value your input, and our philosophy is to enhance our toolset based on customer feedback. If your idea is chosen for development, you will be notified at that time. Your reference number for this Product Idea is PI12090066
If you would like to follow up on your Product Idea at a later point, you may contact Developer Support management via email. Please include the reference number of your Product Idea in the subject and body of your email message. You can reach Developer Support management through the following email address: dsmanager@infragistics.com
Yes, please allow programmatic setting of column widths in future versions.
A useful scenario for this is being able to constrict the maximum or minimum widths of columns when performing the autosize.
Thank you for your post. I have been looking into it and I can say that once you auto - size the Fields after you have set their Width via code, you are able to modify their Width only using the UI. If you want I can log a product idea on your behalf.
Looking forward for your reply.