When a property return type is ArraySegment<T> and properties are auto-generated, an exception is thrown and the control is not displayed.
My example specifically:
public class TestClass{ private readonly ArraySegment<string> _strings; public IReadOnlyList<string> Strings { get { return this._strings; } }}<Grid><Grid.Resources><local:BooleanConverterx:Key="BooleanConverter"/><local:InvBooleanConverterx:Key="InvBooleanConverter"/><local:StringToIntConverterx:Key="StringToIntConverter"/><local:StringToDblConverterx:Key="StringToDblConverter"/><local:SettingValueTemplateSelectorx:Key="SettingValueTemplateSelector"><local:SettingValueTemplateSelector.BooleanTemplate><DataTemplate><StackPanelOrientation="Horizontal"><telerik:RadRadioButtonIsChecked="{Binding Path=Value}"><TextBlockText="Enabled"/></telerik:RadRadioButton><telerik:RadRadioButtonIsChecked="{Binding Path=Value}"><TextBlockText="Disabled"/></telerik:RadRadioButton></StackPanel></DataTemplate></local:SettingValueTemplateSelector.BooleanTemplate><local:SettingValueTemplateSelector.IntTemplate><DataTemplate><telerik:RadNumericUpDownValue="{Binding Path=Value, Converter={StaticResource StringToIntConverter}}"NumberDecimalDigits="0"/></DataTemplate></local:SettingValueTemplateSelector.IntTemplate><local:SettingValueTemplateSelector.DoubleTemplate><DataTemplate><telerik:RadNumericUpDownValue="{Binding Path=Value,Converter={StaticResource StringToDblConverter}}"/></DataTemplate></local:SettingValueTemplateSelector.DoubleTemplate><local:SettingValueTemplateSelector.StringTemplate><DataTemplate><TextBlockText="{Binding Path=Value, Mode=TwoWay}"/></DataTemplate></local:SettingValueTemplateSelector.StringTemplate></local:SettingValueTemplateSelector></Grid.Resources><telerik:RadGridViewx:Name="RadGridView"GroupRenderMode="Flat"RowIndicatorVisibility="Collapsed"CanUserFreezeColumns="False"ItemsSource="{Binding ElementName=Window1, Path=List}"IsReadOnly="false"ScrollMode="Deferred"AutoExpandGroups="True"AutoGenerateColumns="false"Margin="0,2,0,-2"><telerik:RadGridView.Columns><telerik:GridViewDataColumnHeader="Value"IsGroupable="True"DataMemberBinding="{Binding Value}"CellTemplateSelector="{StaticResource SettingValueTemplateSelector}"Background="LightGray"></telerik:GridViewDataColumn><telerik:GridViewDataColumnHeader="ValueType"IsGroupable="True"DataMemberBinding="{Binding ValueType}"Background="LightGray"></telerik:GridViewDataColumn></telerik:RadGridView.Columns></telerik:RadGridView></Grid>
Template selector:publicclassSettingValueTemplateSelector : DataTemplateSelector{publicoverrideDataTemplate SelectTemplate(objectitem, DependencyObject container){if(itemisDataObjecten){DataObjecten model = itemasDataObjecten;if(model.ValueType ==typeof(int))returnthis.IntTemplate;elseif(model.ValueType ==typeof(String))returnthis.StringTemplate;elseif(model.ValueType ==typeof(double))returnthis.DoubleTemplate;elseif(model.ValueType ==typeof(bool))returnthis.BooleanTemplate;elsereturnnull;}returnnull;}}
One of the converters (basic):publicclassStringToIntConverter : IValueConverter{publicobjectConvert(objectvalue, Type targetType,objectparameter, System.Globalization.CultureInfo culture){intretValue=0;if(int.TryParse(value.ToString(),outretValue)){returnretValue;}elsereturn0;}publicobjectConvertBack(objectvalue, Type targetType,objectparameter, System.Globalization.CultureInfo culture){thrownewNotSupportedException("Do not use this converter for objects other than boolean");}}
Model:publicclassDataObject{publicobjectValue {get;set; }publicType ValueType {get;set; }}List.Add(newDataObject() { Value ="8", ValueType =typeof(int) });List.Add(newDataObject() { Value ="8", ValueType =typeof(double) });List.Add(newDataObject() { Value ="8gf", ValueType =typeof(string) });List.Add(newDataObject() { Value = 454365, ValueType =typeof(int) });List.Add(newDataObject() { Value =false, ValueType =typeof(bool) });
<DataGridTemplateColumn x:Name="amountEarnedColumn" Header="Amount Earned" Width="SizeToHeader"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <telerik:RadMaskedCurrencyInput Value="{Binding AmountEarned}" Mask="c5.2" Placeholder=" " /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <telerik:RadMaskedCurrencyInput Value="{Binding AmountEarned}" /> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>
Hi,
We are using MVVM model. There are two grids parent and Child. Child Grid will be loaded on selecting any Parent row. Child grid will have all cells in Edit mode on Cell Focus and any change done to the cells will be auto saved. The task is to reload the Parent and Child grid when any concurrency exception occurs while auto saving Cells in Child grid. Below code is used to raise an Concurrency exception in viewmodel which is handled to display message box. Once the message is shown dispatcher exception is occuring.
Can you suggest any solution to avoid the Dispatcher exception?
Xaml.cs
---------
private void childgrd_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
{
viewmodel.HandleCellEditEnded(e.Cell.Column.DisplayIndex);
viewmodel.HeaderSelected = e.Cell.Column.Header.ToString();
}
viewmodel
-------------
public void HandleCellEditEnded(int Column)
{
Update();
}
public void Update()
{
try
{
//Save child grid changes
}
catch (DbUpdateConcurrencyException)
{
MessageBox.Show("Concurrency exception occured");
SelectedParent = null;
ParentGridCollection = null;
SelectedChild = null;
childGridCollection = null;
LoadParent();
}
}
Regards,
Vinetha.P