我已经确认,在Xamarin Forms UWP项目的App.xaml ResourceDictionary中仅存在以下样式(即使未使用),即使启用.NET本机工具链进行编译,也会导致UWP应用启动时崩溃在发布模式下(x64,但在这种情况下不要紧)。在未启用.NET本机工具链的情况下,可以100%正常运行,但确实希望保留这种自定义样式,并从本机编译的更快应用程序中获得收益。有人知道为什么它导致应用程序崩溃吗?除了我在Windows事件查看器中看到的信息外,我什至无法弄清楚如何获得更详细的错误消息,该事件只是说Windows.UI.Xaml.dll是错误的模块名称。
更新:通过关闭“优化代码”并在发布模式下启用DEBUG并从VS运行,我可以得到以下内容。...这导致我进入了一个我使用的[great]动画库,名为Xamanimation ...仍然不确定我的UWP app.xaml中的自定义样式与此问题之间的链接,但是解决此实际问题当然可以解决所有问题(即,样式是红色鲱鱼)。在下面添加了对此的答案。
System.Private.Interop.dll!System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(int hr,System.RuntimeTypeHandle typeHnd)Line 1189 at f:\ dd \ ndp \ fxcore \ CoreRT \ src \ System.Private.Interop \ src \共享\ McgMarshal.cs(1189)
System.ArgumentException HResult = 0x80070057 Message =值不在预期范围内。Source = StackTrace:StackTrace“位于System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32 hr,RuntimeTypeHandle typeHnd),位于f:\ dd \ ndp \ fxcore \ CoreRT \ src \ System.Private.Interop \ src \ Shared \ McgMarshal.cs :line 1189 \ r \ n在__Interop.ComCallHelpers.Call(__ ComObject __this,RuntimeTypeHandle __typeHnd,Int32 __targetIndex,Double arg0)\ r \ n
在__Interop.ForwardComStubs.Stub_22 [TThis](__ ComObject __this,Double value,Int32 __targetIndex) r \ n在Windows.UI.Xaml.IUIElement__Impl.Stubs.put_Opacity(__ ComObject __this,Double value)\ r \ n在Windows.UI.Xaml.UIElement.put_Opacity(Double value)\ r \ n在Xamarin.Forms.Platform .UWP.VisualElementTracker2.UpdateOpacity(VisualElement view, FrameworkElement frameworkElement) in D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\VisualElementTracker.cs:line 518\r\n at Xamarin.Forms.Platform.UWP.VisualElementTracker
2. D:\ a \ 1 \ s \ Xamarin.Forms.Platform.UAP \ VisualElementTracker.cs中的UpdateNativeControl():Xamarin.Forms.Platform.UWP.VisualElementTracker的236行\ r \ n2.OnRedrawNeeded(Object sender, EventArgs e) in D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\VisualElementTracker.cs:line 409\r\n at System.EventHandler
1.Invoke(对象发送方, TEventArgs e)\ r \ n位于D:\ a \ 1 \ s \ Xamarin.Forms.Core \ VisualElement.cs:line 572 \ r \ n位于Xamarin.Forms.AnimationExtensions的Xamarin.Forms.VisualElement.BatchCommit()中。 D:\ a \ 1 \ s \ Xamarin.Forms.Core \ AnimationExtensions.cs:Line 274 \ r \ n
在System.EventHandler.InvokeOpenStaticThunk(Object sender,EventArgs e)\ r \中的HandleTweenerUpdated(Object o,EventArgs args)在D:\ a \ 1 \ s \ Xamarin.Forms.Core \ Tweener.cs中的Xamarin.Forms.Tweener.b__22_0(Int64 step)处的System.EventHandler.Invoke(Object sender,EventArgs e)\ r \ n中: System.Func的第92 \ r \ n行2.Invoke(T arg)\r\n at Xamarin.Forms.Internals.Ticker.SendSignals(Int64 step) in D:\\a\\1\\s\\Xamarin.Forms.Core\\Internals\\Ticker.cs:line 136\r\n
1.在__Interop.Intrinsics.HasThisCall__51(对象__this,IntPtr pfn,对象arg0,对象arg1)上调用(对象发送者,TEventArgs e)\ r \ n在__Interop.ReverseComStubs.Stub_41(对象__this,无效*不安全的发送者) ,Void * unsafe_args,IntPtr __methodPtr)“字符串
at Xamarin.Forms.Internals.Ticker.SendSignals(Int32 timestep) in D:\\a\\1\\s\\Xamarin.Forms.Core\\Internals\\Ticker.cs:line 125\r\n
at Xamarin.Forms.Platform.UWP.WindowsTicker.RenderingFrameEventHandler(Object sender, Object args) in D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\WindowsTicker.cs:line 25\r\n at System.EventHandler
<Style x:Key="FormTextBoxStyle" TargetType="uwp:FormsTextBox">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="ForegroundFocusBrush" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" />
<Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" />
<Setter Property="PlaceholderForegroundFocusBrush" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" />
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
<Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
<Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
<Setter Property="BorderThickness" Value="0,0,0,2" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="uwp:FormsTextBox">
<Grid>
<Grid.Resources>
<Style x:Name="DeleteButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid
x:Name="ButtonLayoutGrid"
Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}"
BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock
x:Name="GlyphElement"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
FontStyle="Normal"
Foreground="{TemplateBinding Foreground}"
Text="" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border
x:Name="BackgroundElement"
Grid.Row="1"
Grid.RowSpan="1"
Grid.ColumnSpan="2"
Margin="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}" />
<Border
x:Name="BorderElement"
Grid.Row="1"
Grid.RowSpan="1"
Grid.Column="0"
Grid.ColumnSpan="2"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<ContentPresenter
x:Name="HeaderContentPresenter"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
VerticalAlignment="Bottom"
VerticalContentAlignment="Bottom"
x:DeferLoadStrategy="Lazy"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="Normal"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
Visibility="Collapsed" />
<ScrollViewer
x:Name="ContentElement"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
Foreground="{TemplateBinding ForegroundFocusBrush}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsTabStop="False"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
ZoomMode="Disabled" />
<ContentControl
x:Name="PlaceholderTextContentPresenter"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{TemplateBinding PlaceholderText}"
Foreground="{TemplateBinding PlaceholderForegroundBrush}"
IsHitTestVisible="False"
IsTabStop="False" />
<Button
x:Name="DeleteButton"
Grid.Row="1"
Grid.Column="1"
MinWidth="34"
Margin="{ThemeResource HelperButtonThemePadding}"
VerticalAlignment="Stretch"
BorderThickness="{TemplateBinding BorderThickness}"
FontSize="{TemplateBinding FontSize}"
Foreground="{TemplateBinding ForegroundFocusBrush}"
IsTabStop="False"
Style="{StaticResource DeleteButtonStyle}"
Visibility="Collapsed" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BackgroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{Binding ForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="RequestedTheme">
<DiscreteObjectKeyFrame KeyTime="0" Value="Light" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ButtonStates">
<VisualState x:Name="ButtonVisible">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ButtonCollapsed" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
显然,使用Xamanimation库向我的ContentPage Appearing事件中的某些项目添加动画的这种小技巧不适用于FadeToAnimation(尽管对于TranslateToAnimation而言也很好):
<xamanimation:StoryBoard x:Key="EntriesAnimation" Target="{x:Reference UserEntries}">
<xamanimation:FadeToAnimation Opacity="0" Duration="0" />
<xamanimation:FadeToAnimation Opacity="1" Duration="500" />
</xamanimation:StoryBoard>
在调试模式下或在禁用.NET Native编译的发行版中,此操作没有问题。但是启用它后,它使应用程序崩溃了。
解决方法很简单,我只是直接将Target上的Opacity属性设置为0,并摆脱了第一行(<xamanimation:FadeToAnimation Opacity="0" Duration="0" />
)和presto-一切都很好。