If a column is sized with InitialAuto, which will also happen if they double click on the column separator to auto size the column, how do you determine the actual size of the column?
The column's ActualWidth property is 0.0 (zero) in this case, and the Width and WidthResolved properties only tell you that it's sized to InitialAuto. I need the real width in pixels that the column is actually sized to.
Thanks,
Mike
HI,
You could get the size of the the first cell and used that width.
Here a code snippet:
CellValuePresenter cvp = CellValuePresenter.FromCell(xgrid1.ActiveCell);
MessageBox.Show(cvp.ActualWidth.ToString());
Sincerely,
Matt
Developer Support Engineer
That seems to be a WPF class for XamDataGrid, not a Silverlight class for XamGrid (which is what I'm asking about).
Anything for Silverlight?
Hello Mike,
Thank you for your feedback. I am a little confused what exactly is your scenario. Would you please attach a sample application with steps in order to reproduce it and investigate it ?
Looking forward to hearing from you.
Sorry for the delay. I had to trim down our application to a reasonably small sample program that still demonstrates the problem. It turns out that it's more complicated that I originally thought (a xamGrid in a TabControl with grouping is required).
I have put together a whole sample, and includes a detailed document showing exactly what needs to be done to reproduce the issue, including exactly what I'm seeing, etc. See the attached ColumnWidths.zip.
I hope this will allow you to find a solution (work around will be fine).
Thank you for the provided sample application and your explanation. Your issue occurs because the XamGrid in the second tab item is not initialized when you are trying to get the value for the columns.
I can suggest you to handle the ‘Loaded’ event of the TabControl and to switch through the tabs like e.g. :
private void tabControl_Loaded(object sender, RoutedEventArgs e)
{
tabControl.SelectedItem = tabControl.Items[1];
Dispatcher.BeginInvoke(new Action(() => tabControl.SelectedItem = tabControl.Items[0]));
tabControl.SelectedItem = tabControl.Items[0];
}
This way you can get the desired results.
That doesn't look like it works (reliably?). When I added that code most of the time I get the 0 column widths, but sometimes I do get the right widths. Do a refresh on the browser and the press the button immediately.
I actually have code (in my big application) that iterates over all the tab, doing DispatcherBeginInvoke every time I change the tab, and for each tab I expand the groups (again, using Dispatcher.BeginInvoke) to ensure things are loaded, and it still doesn't work. I've even tried doing many Dispatcher.BeginInvoke's.
There's something else going on here, but I can't figure out what it is.
Any ideas?
The issue that you are having does not depend on the XamGrid. In order to get the ‘ActualWidth’ the control must be initialized and its columns to be drown. It seems that the time for looping through your all tab items is not necessary the group columns to be initialized.
Hi Mike,
I have been trying to find out some other approach in order to delay an operation execution but my tries was without success.
This scenario seems not related to any Infragistics product so I can suggest you ask for a suggestion in the MSDN community, as the operation execution is related to .Net scenarios.
If you need any further assistance on this matter, feel free to ask.
That sounds right.
I was hoping that using Dispatcher.BeginInvoke after changing to each tab item would do it, but apparently it doesn't. Is there something else you can suggest?