加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

在App.xaml上添加BasedOn Style正在崩溃App(){InitializeCompone

发布时间:2020-12-14 02:51:14 所属栏目:Windows 来源:网络整理
导读:将项目调整为 Template10 ,我在App.xaml中继承了继承的样式. 它看起来像Template10,不支持继承或扩展样式.我试图从TitleStyle扩展SubTitleStyle但我在XamlTypeInfo.g.cs中的GetXamlType上获得了COM异常 我的App.xaml.cs sealed partial class App : BootStra
将项目调整为 Template10,我在App.xaml中继承了继承的样式.

它看起来像Template10,不支持继承或扩展样式.我试图从TitleStyle扩展SubTitleStyle但我在XamlTypeInfo.g.cs中的GetXamlType上获得了COM异常

我的App.xaml.cs

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()

解决方法

这让我非常困惑.我很容易重现这一点.然后,我很容易在不引用模板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平台上发现了一个真正的错误.

这是我们更新模板10之前唯一的当前解决方法.

<Page.Resources>
    <ResourceDictionary Source="..StylesCustom.xaml" />
</Page.Resources>

我的意思是,你在页面而不是在App中完成工作.那么,如果不修复XAML平台,我们将如何修复模板10?看看我们将在Bootstrapper中使用的这个令人难以置信的代码:

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;
}

错误,至少是在迭代器的count属性中,当你迭代它时,它似乎递增而不是递减.疯了吧?事实证明,这个迭代路径不是常见的用例.但是,现在没关系,我们在这里提出了问题.

我将在本周的某个时候更新模板10.

祝你好运,杰里

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读