Hi Joe,
Is it possible to make the Field to size to content when double-clicking the splitter between fields? You know it is possible to include many columns to display for a grid in practice, so the field headers are easily clipped. Considering lacking of support to size to content for a cell, I just want to find a way to make users easily see the whole header string at least.
I used the PreviewMouseDoubleClick event to capture user's double-clicking action to the splitter between fields, but I don't know what should be done in the hanlder of this event to make the selected field to become wider to display its whole header string. Could give me a some suggestion or another good solutions?
Thanks your any help.
Corin
Joe,
Thanks for your help very much, for my case, it works very well.
Also I wish to take this opportunity to provide a case to those that want column to size to content. In my case, because the ability of size to content for all cells are unavailable, to compensate for this, I just made the column(including all the corresponding cells) to size to content on double click a field/cell, or the divider between field/cell. In this way, it can't result in a very 'choppy' displaly as Joe described, but in the meantime, it meets users basic requirement, that is, to display the information they are focused on wholly. Sure it's the best if there is the ability to size to content for the whole Grid. Hope there are many hot improvements in its next release.
Thanks,
Thanks your reply very much, it works very well.
Now I have another question, How to make the Cell to size to content? In my case, I also want to make all the corresponding cells to size to content when double-clicking a splitter between fields, I mean just the cells belonging to the selected field, not the whole cells in the grid. I couldn't find a good way to approach this.
Thank your soon reply.
private void ResizeFieldLabelToContents(Field field) { if (field == null) return; // Only attempt to resize the Field's Label if the Label is a string. if (field.Label is string) { // Create a dummy LabelPresenter to use for measuring the Label text. LabelPresenter lp = new LabelPresenter(); lp.Content = (string)field.Label; lp.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // Set the Width of the Field's Label field.Settings.LabelWidth = double.NaN; field.Settings.LabelWidth = lp.DesiredSize.Width; } }
private void ResizeFieldLabelToContents(Field field)
{
if (field == null) return; // Only attempt to resize the Field's Label if the Label is a string. if (field.Label is string) { // Create a dummy LabelPresenter to use for measuring the Label text. LabelPresenter lp = new LabelPresenter(); lp.Content = (string)field.Label; lp.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // Set the Width of the Field's Label field.Settings.LabelWidth = double.NaN; field.Settings.LabelWidth = lp.DesiredSize.Width; }
if (field == null)
return;
// Only attempt to resize the Field's Label if the Label is a string.
if (field.Label is string)
// Create a dummy LabelPresenter to use for measuring the Label text. LabelPresenter lp = new LabelPresenter(); lp.Content = (string)field.Label; lp.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // Set the Width of the Field's Label field.Settings.LabelWidth = double.NaN; field.Settings.LabelWidth = lp.DesiredSize.Width;
// Create a dummy LabelPresenter to use for measuring the Label text.
LabelPresenter lp = new LabelPresenter();
lp.Content = (string)field.Label;
lp.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
// Set the Width of the Field's Label
field.Settings.LabelWidth = double.NaN;
field.Settings.LabelWidth = lp.DesiredSize.Width;
}