首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Windows应用程序-灾难性故障( HRESULT: 0x8000FFFF (E_UNEXPECTED)例外)

Windows应用程序-灾难性故障( HRESULT: 0x8000FFFF (E_UNEXPECTED)例外)
EN

Stack Overflow用户
提问于 2013-11-18 22:14:08
回答 2查看 8.6K关注 0票数 1

我试图在C#中编写一个小型库,以便将一些类和UI元素重用到不同的项目中。

我想放在这个库中的一个UI元素是一个非常简单的UserControl:

代码语言:javascript
运行
复制
<UserControl
    x:Class="MyProjet.UiUtil.Progress"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyProjet.UiUtil"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <UserControl.Resources>
        <Style x:Key="BasicTextStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="{StaticResource ApplicationForegroundThemeBrush}"/>
            <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="TextTrimming" Value="WordEllipsis"/>
            <Setter Property="TextWrapping" Value="Wrap"/>
            <Setter Property="Typography.StylisticSet20" Value="True"/>
            <Setter Property="Typography.DiscretionaryLigatures" Value="True"/>
            <Setter Property="Typography.CaseSensitiveForms" Value="True"/>
        </Style>

        <Style x:Key="BaselineTextStyle" TargetType="TextBlock" BasedOn="{StaticResource BasicTextStyle}">
            <Setter Property="LineHeight" Value="20"/>
            <Setter Property="LineStackingStrategy" Value="BlockLineHeight"/>
            <!-- Aligne correctement le texte sur sa ligne de base -->
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="4"/>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HeaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource BaselineTextStyle}">
            <Setter Property="FontSize" Value="56"/>
            <Setter Property="FontWeight" Value="Light"/>
            <Setter Property="LineHeight" Value="40"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-2" Y="8"/>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="SubheaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource BaselineTextStyle}">
            <Setter Property="FontSize" Value="26.667"/>
            <Setter Property="FontWeight" Value="Light"/>
            <Setter Property="LineHeight" Value="30"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="6"/>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid x:Name="GridRoot" Width="{Binding Path=GridWidth}" Height="{Binding Path=GridHeight}" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>            

        <TextBlock x:Name="TxtTitle" Grid.Row="0" Text="{Binding Path=Title}" Style="{StaticResource HeaderTextStyle}" TextAlignment="Center" TextWrapping="Wrap" Margin="12,12,12,0" VerticalAlignment="Center" HorizontalAlignment="Center" />

        <StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBlock x:Name="TxtDescription" Text="{Binding Path=Description}" TextAlignment="Center" Style="{StaticResource SubheaderTextStyle}" TextWrapping="Wrap" />
            <ProgressBar IsIndeterminate="True" Margin="0, 15" Width="350" />
        </StackPanel>
    </Grid>
</UserControl>

而背后的密码是:

代码语言:javascript
运行
复制
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace MyProjet.UiUtil
{
    public sealed partial class Progress
    {
        /// <summary>
        /// Inner class for MVVM.
        /// </summary>
        public sealed class ViewModelProgress
        {
            public string Title { get; set; }

            public string Description { get; set; }

            public double GridHeight
            {
                get
                {
                    return Window.Current.Bounds.Height;
                }
            }

            public double GridWidth
            {
                get
                {
                    return Window.Current.Bounds.Width;
                }
            }
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="titleForeground"></param>
        /// <param name="descriptionForeground"></param>
        public Progress(string title, string description, Brush backgroundColor, Brush titleForeground, Brush descriptionForeground)
        {
            InitializeComponent();

            GridRoot.Background = backgroundColor;
            TxtTitle.Foreground = titleForeground;
            TxtDescription.Foreground = descriptionForeground;

            this.DataContext = new ViewModelMBProgressHUD() { Title = title, Description = description };
        }
    }
}

这里有一个示例,说明如何在Windows应用程序的MainPage中使用此用户控件:

代码语言:javascript
运行
复制
using System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace SampleProject
{
    public sealed partial class MainPage
    {
        private Popup _popup;

        private DispatcherTimer _timer;

        public MainPage()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _popup = new Popup() { Child = new Progress("Mon Titre", "Ma description", new SolidColorBrush(Colors.Magenta), new SolidColorBrush(Colors.Green), new SolidColorBrush(Colors.Orange)), IsOpen = false };
            _timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(5) };
            _timer.Tick += timer_Tick;
        }

        private void timer_Tick(object sender, object e)
        {
            _timer.Stop();
            _popup.IsOpen = false;
            BtnDisplay.IsEnabled = true;
        }

        private void BtnDisplay_Click(object sender, RoutedEventArgs e)
        {
            BtnDisplay.IsEnabled = false;
            _timer.Start();
            _popup.IsOpen = true;
        }
    }
}

当我将UserControl文件复制到示例项目中时,一切正常工作,但是当我从库中使用UserControl (包为nuget依赖项)时,我有以下错误消息和代码:

灾难性故障( HRESULT: 0x8000FFFF (E_UNEXPECTED)除外) Windows.UI.Xaml.Controls.Frame.NavigationFailed未被处理。

我在互联网上读到,评论或取消评论这句话会有帮助:

代码语言:javascript
运行
复制
base.OnNavigatedTo(e);

对我来说,这不会改变任何事情..。

希望有人能帮我!

提前通知你!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-09 15:22:08

我所犯的错误似乎与这个主题有关:http://support.microsoft.com/kb/2739194/en-us

票数 1
EN

Stack Overflow用户

发布于 2016-03-22 10:39:00

当我得到这个错误(没有其他内部异常)时-它被链接到一个DsiplayMemberPath属性在一个ListView。删除它会使它再次工作。

这个人似乎也有类似的问题,但没有明确原因导致错误。

作为一种解决办法,我重写了模型对象上的ToString方法,以显示我想要的属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20059062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档