Windows应用商店应用程序-灾难性故障(HRESULT中的异常:0x8000FFFF(E_UNEXPECTED))



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

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

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

以及背后的代码:

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应用商店应用程序主页的示例:

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文件复制到Sample项目中时,一切都很好,但当我使用库中的UserControl(作为nuget依赖项的包)时,我遇到了一个问题,我有以下错误消息和代码:

灾难性故障(HRESULT中的异常:0x8000FFFF(E_expected))

Windows.UI.Xaml.Controls.Frame.NavigationFailed未处理。

我在互联网上读到,评论或取消注释这一行可以帮助:

base.OnNavigatedTo(e);

就我而言,它不会改变任何事情。。。

希望有人能帮助我!

提前问你!

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

当我得到这个错误(没有其他内部异常)时,它被链接到ListView中的DsiplayMemberPath属性。删除此项后,它可以重新工作。

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

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

相关内容

最新更新