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

时间:2013-11-18 22:14:09

标签: c# user-controls windows-store-apps windows-store

我正在尝试用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_UNEXPECTED))

     

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

我已在互联网上阅读评论或取消注释此行可以提供帮助:

base.OnNavigatedTo(e);

在我的情况下,它不会改变任何东西......

希望有人能够帮助我!

提前告诉你!

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

当我收到此错误(没有其他内部异常)时 - 它已链接到DsiplayMemberPath中的ListView属性。删除它会导致它再次起作用。

this person似乎有一个类似的问题,没有明确的理由导致错误。

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