I have an application in which I list some elements and then change them to another page for editing. On the edit page, I have several fields where I need to select a value from the list that I load on another page. I call the list page from the edit page, passing the method from the view model of the edit page, which will be called upon selection so that I can update my model and bindings.
The problem is that sometimes, returning to the edit page, the debugger breaks in the generated App.gics file with
"Error HRESULT E_FAIL has been returned from a call to a COM component." exception.
It fully displays the page with the correct bindings and selected values before splitting.
I excluded possible errors from asynchronously loading the list of values, replacing it with a dummy page and deleting any callbacks set on the edit page. An error still occurred. On the edit page there is a navigation caching mode set to "Required", so I do not lose previous changes. I tried without caching mode and still got an error.
The only thing that seemed to solve the problem was to remove the bindings that the custom converters used on the xaml edit page, but I have the ones on the other pages and I had no problems. (See update)
The debugger is broken into the generated code:
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
This is the xaml for the edit page:
<Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BoolToVisibility" />
<converters:StringFormatConverter x:Key="StringFormat" />
<converters:DateTimeToDateTimeOffsetConverter x:Key="DateOffset" />
<converters:DateTimeToTimeSpanConverter x:Key="TimeSpan" />
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<fieldSelectControl:BackButtonAndTitle Title="Page Title" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Name="HomeButton"
Width="70"
Height="50"
Background="Black"
Content=""
FontFamily="Segoe MDL2 Assets"
FontSize="30" />
<TextBlock Name="PageTitle"
FontSize="36"
Text="{Binding OrderTitle}" />
</StackPanel>
<ProgressRing Grid.Row="2" IsActive="{Binding IsLoading}" />
<ScrollViewer Grid.Row="2"
Height="Auto"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Visibility="{Binding Path=FinishedLoading,
Converter={StaticResource BoolToVisibility}}">
<StackPanel Margin="20,10,20,30">
<TextBlock Margin="0,5,0,5"
Style="{StaticResource DetailLabel}"
Text="Date" />
<DatePicker Date="{Binding Day, Mode=TwoWay, Converter={StaticResource DateOffset}}" />
<TextBlock Margin="0,15,0,5"
Style="{StaticResource DetailLabel}"
Text="Type" />
<ComboBox ItemsSource="{Binding ComboValues}" SelectedItem="{Binding SelectedHourType, Mode=TwoWay}" />
<TextBlock Margin="0,15,0,5"
Style="{StaticResource DetailLabel}"
Text="Start" />
<TimePicker ClockIdentifier="24HourClock" Time="{Binding StartTime, Mode=TwoWay, Converter={StaticResource TimeSpan}}" />
<TextBlock Margin="0,5,0,5"
Style="{StaticResource DetailLabel}"
Text="End" />
<TimePicker ClockIdentifier="24HourClock" Time="{Binding EndTime, Mode=TwoWay, Converter={StaticResource TimeSpan}}" />
<TextBlock Margin="0,15,0,5"
Style="{StaticResource DetailLabel}"
Text="Amount" />
<TextBox InputScope="Number" Text="{Binding HValue, Mode=TwoWay}" />
<fieldSelectControl:FieldWithIconSelector x:Name="fsSelect"
IconClickedEvent="btnClose_Click"
IconField=""
TitleField="Add..."
TitleIconField=""
ValueField="" />
<ScrollViewer Height="Auto"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<ListView x:Name="lstOrders"
Height="auto"
MaxHeight="600"
HorizontalAlignment="Stretch"
IsItemClickEnabled="True"
ItemClick="lstOrders_ItemClick"
ItemsSource="{Binding SelectedEmployees,
Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:Responsible">
<fieldSelectControl:FieldWithIconSelector x:Name="fsEmployees"
IconClickedEvent="fsEmployees_IconClickedEvent"
IconField=""
TitleField=""
TitleIconField=""
ValueField="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</ScrollViewer>
<Button Name="btnSave"
Margin="0,20,0,15"
HorizontalAlignment="Stretch"
Click="btnSave_Click"
Visibility="{Binding Path=FinishedSaving,
Converter={StaticResource BoolToVisibility}}">
<Button.Template>
<ControlTemplate>
<StackPanel HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#0099cc"
Orientation="Vertical"
Padding="5">
<TextBlock HorizontalAlignment="Center"
FontFamily="Segoe MDL2 Assets"
FontSize="25"
Text="" />
<TextBlock HorizontalAlignment="Center" Text="Save" />
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</ScrollViewer>
</Grid>
Code for DateOffset converter:
public class DateTimeToDateTimeOffsetConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
try
{
if (value is DateTime)
{
DateTime date = (DateTime)value;
return new DateTimeOffset(date);
}
else
return new DateTimeOffset(DateTime.Now);
}
catch (Exception ex)
{
return new DateTimeOffset(DateTime.Now);
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
DateTimeOffset dto = (DateTimeOffset)value;
return dto.DateTime;
}
}
Code for TimeOffset Converter:
public class DateTimeToTimeSpanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
try
{
if (value is DateTime)
{
DateTime date = (DateTime)value;
return new TimeSpan(date.Ticks);
}
else
return new TimeSpan(DateTime.Now.Ticks);
}
catch (Exception ex)
{
return new TimeSpan(DateTime.Now.Ticks);
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
TimeSpan ts = (TimeSpan)value;
DateTime dt = new DateTime(ts.Ticks);
return dt;
}
}
, , , , xaml, , , , , , , .
?
UPDATE
, , , . . , , , , , , .
, Back . , Frame.GoBack() .