Hi
My problem is simple and easy to repeat. Whenever I click on a column header in my XamWebGrid control the application/silverlight/browser goes into an infinite loop and must be killed. Everything else in the grid works fine, I can click my checkbox and they update the view model they are bound to. I am not sure what is causing this so I have included all the relevant details below.
I have the following XamWebGrid template for which I am dynamically generating the columns based on other controls selected else where.
<infragistics_DG:XamWebGrid x:Name="ContentGrid"
AutoGenerateColumns="False"
Margin="{TemplateBinding Margin}"
MaxDepth="3"
DeleteKeyAction="None">
<infragistics_DG:XamWebGrid.ColumnMovingSettings>
<infragistics_DG:ColumnMovingSettings AllowColumnMoving="Disabled"/>
</infragistics_DG:XamWebGrid.ColumnMovingSettings>
<infragistics_DG:XamWebGrid.FilteringSettings>
<infragistics_DG:FilteringSettings AllowFilterRow="None"/>
</infragistics_DG:XamWebGrid.FilteringSettings>
<infragistics_DG:XamWebGrid.ExpansionIndicatorSettings>
<infragistics_DG:ExpansionIndicatorSettings>
<infragistics_DG:ExpansionIndicatorSettings.Style>
<Style TargetType="igPrim:ExpansionIndicatorCellControl">
<Setter Property="Background" Value="Transparent"/>
</Style>
</infragistics_DG:ExpansionIndicatorSettings.Style>
</infragistics_DG:ExpansionIndicatorSettings>
</infragistics_DG:XamWebGrid.ExpansionIndicatorSettings>
<infragistics_DG:XamWebGrid.RowSelectorSettings>
<infragistics_DG:RowSelectorSettings Visibility="Collapsed" EnableRowNumbering="False"/>
</infragistics_DG:XamWebGrid.RowSelectorSettings>
<infragistics_DG:XamWebGrid.AddNewRowSettings>
<infragistics_DG:AddNewRowSettings AllowAddNewRow="None"/>
</infragistics_DG:XamWebGrid.AddNewRowSettings>
<infragistics_DG:XamWebGrid.EditingSettings>
<infragistics_DG:EditingSettings AllowEditing="None" />
</infragistics_DG:XamWebGrid.EditingSettings>
</infragistics_DG:XamWebGrid>
the code for generating the columns is,
ColumnBaseCollection columns = grid.Columns;
columns.Clear();
var branchNameCol = new TextColumn();
branchNameCol.Key = "TradingBranchLegalEntityAgreement.LegalEntity.Name";
branchNameCol.HeaderText = "Branch Name";
columns.Add(branchNameCol);
var branchProductLookupConverter = new BranchProductDictionaryLookupConverter();
foreach (Product product in BranchProductTable.DisplayProducts)
{
var productCol = new UnboundColumn();
productCol.Key = product.Id;
productCol.HeaderText = product.ShortName;
productCol.ValueConverter = branchProductLookupConverter;
productCol.ValueConverterParameter = product.Id;
productCol.HorizontalContentAlignment = HorizontalAlignment.Center;
productCol.HeaderStyle = new Style(typeof(HeaderCellControl));
productCol.HeaderStyle.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Center));
productCol.HeaderTemplate = (DataTemplate)XamlReader.Load(
string.Format(
@"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:layout='clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit'>
<layout:LayoutTransformer>
<layout:LayoutTransformer.LayoutTransform>
<RotateTransform Angle='-80'/>
</layout:LayoutTransformer.LayoutTransform>
<TextBlock Text='{0}'/>
</layout:LayoutTransformer>
</DataTemplate>",
product.ShortName.Replace("&", "&")));
productCol.ItemTemplate = (DataTemplate)XamlReader.Load(
@"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
<CheckBox IsChecked='{Binding Value.IsSelected, Mode=TwoWay}'/>
</DataTemplate>");
columns.Add(productCol);
}
Ok, I've just discovered that switching off sorting fixes this problem for me.
<infragistics_DG:XamWebGrid.SortingSettings> <infragistics_DG:SortingSettings AllowSorting="False"/></infragistics_DG:XamWebGrid.SortingSettings>
Nether the less having an unbound column with a custom template shouldn't crash my browser when sorting is enabled.
Hi,
The ValueConverter on the UnboundColumn is used for sorting.
So my guess is you have some sort of logic inside there which is causing the app to hang.
-SteveZ
Steve,
This is my value converter code.
public class BranchProductDictionaryLookupConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var branchProductTableRowItem = value as BranchProductTableRowItem; if (branchProductTableRowItem != null) { BranchProductSelectionItem item = branchProductTableRowItem.CurrentSelectionView parameter as string]; return item; } throw new NotImplementedException(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }}
Obviously I'm not returning a simple type that has any Comparison/IComparer method is this what the problem is? How does the sort method use the IValueConverter to sort columns?
Ok I see that. I will make the fix to my usage of the grid.
But maybe you should fix the sorting code to either abort the sort (siliently recover) or throw an exception (alert dev/ tester) rather than go into an infinite loop.
Yes, that is definitely a problem.
Essentially, the xamWebGrid, will call the ValueConverter for each cell, and then try to compare it. If it doesn't implement IComparer, it would throw exceptions.
If you can't implement IComparer<T> on your object, you can write a custom one, and set it on the Column explicitly via the SortComparer property.
Hope this helps,