在App.xaml上添加BasedOn样式在App(){InitializeComponent();}上崩溃
为了使项目适应,我在App.xaml中使用了继承的样式。xaml正在崩溃 它看起来像Template10,不支持继承或扩展样式。我试图从TitleStyle扩展SubTitleStyle,但我在XamlTypeInfo.g.cs中的GetXamlType上得到了一个COM异常 我的App.xaml.cs在App.xaml上添加BasedOn样式在App(){InitializeComponent();}上崩溃,xaml,windows-10,win-universal-app,template10,Xaml,Windows 10,Win Universal App,Template10,为了使项目适应,我在App.xaml中使用了继承的样式。xaml正在崩溃 它看起来像Template10,不支持继承或扩展样式。我试图从TitleStyle扩展SubTitleStyle,但我在XamlTypeInfo.g.cs中的GetXamlType上得到了一个COM异常 我的App.xaml.cs sealed partial class App : BootStrapper { public App() { InitializeComponent(); } public
sealed partial class App : BootStrapper
{
public App() { InitializeComponent(); }
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
NavigationService.Navigate(typeof(ShellView))
await Task.CompletedTask;
}
}
我的App.xaml
<Style x:Key="TitleStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource TextTitleForeground}"/>
<Setter Property="FontSize" Value="26"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="FontWeight" Value="Medium"/>
</Style>
<Style x:Key="SubTitleStyle" TargetType="TextBlock" BasedOn="{StaticResource TitleStyle}">
<Setter Property="Foreground" Value="{StaticResource TextForeground}"/>
<Setter Property="FontSize" Value="20"/>
</Style>
例外信息:
Error HRESULT E_FAIL has been returned from a call to a COM component.
at System.Runtime.InteropServices.WindowsRuntime.IIterator`1.MoveNext()
at System.Runtime.InteropServices.WindowsRuntime.IteratorToEnumeratorAdapter`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Template10.Common.BootStrapper.<InitializeFrameAsync>d__77.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Template10.Common.BootStrapper.<InternalLaunchAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
调用COM组件时返回错误HRESULT E_FAIL。
在System.Runtime.InteropServices.WindowsRuntime.IIterator`1.MoveNext()中
在System.Runtime.InteropServices.WindowsRuntime.IteratorToEnumeratorRadapter`1.MoveNext()中
位于System.Linq.Enumerable.WhereEnumerableInterator`1.MoveNext()
在Template10.Common.BootStrapper.d_u77.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在Template10.Common.BootStrapper.d_u53.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.CompilerServices.AsyncMethodBuilderCore.c.b_uu6_0(对象状态)中
位于System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()处
这让我非常困惑。我很容易就能复制这个。然后,我可以很容易地复制这个,而不需要参考模板10。有问题的代码是T10中的此块:
// title
foreach (var resource in Application.Current.Resources
.Where(x => x.Key.Equals(typeof(Controls.CustomTitleBar))))
{
var control = new Controls.CustomTitleBar();
control.Style = resource.Value as Style;
}
您可以将其简化为:
var a = Application.Current.Resources.ToArray();
放置在任何应用程序的OnLaunched
中。繁荣当我们试图访问资源集合时,但只有在资源中添加了BasedOn
样式时,才会出现错误本身
在与平台团队坐下来为模板10辩护后,桌旁的每个人都开始挠头。当我意识到@dachibox时,你在XAML平台上发现了一个真正的bug
在我们更新模板10之前,这里是当前唯一的解决方法
<Page.Resources>
<ResourceDictionary Source="..\Styles\Custom.xaml" />
</Page.Resources>
错误至少存在于迭代器的count属性中,当您遍历它时,它似乎是递增的而不是递减的。疯了吧?事实证明,这个迭代路径不是一个常见的用例。但是,现在这不重要了,多亏了你的提问,我们已经升起了旗帜
我将在本周的某个时候更新模板10
祝你好运,Jerry请编辑你的问题以包含你的实际源代码。不要链接到代码的图片。至于您的问题,您应该更加清楚在运行代码时发生了什么。您是否收到任何错误消息?他们怎么说?我用更多的细节更新我的问题。欢迎提供更多详细信息的建议:)。谢谢哇!我很高兴能够为XAML平台做出贡献。如果你需要更多的细节,别犹豫问我。哇,我也遇到了同样的问题。只要我的风格不是基于其他任何东西,我就可以走了。
int count = Application.Current.Resources.Count;
foreach (var resource in Application.Current.Resources)
{
var k = resource.Key;
if (k == typeof(Controls.CustomTitleBar))
{
var s = resource.Value as Style;
var t = new Controls.CustomTitleBar();
t.Style = s;
}
count--;
if (count == 0) break;
}