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
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;
}
Joe,
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.