【问题标题】:Settings screen for app is throwing an exception应用程序的设置屏幕引发异常
【发布时间】:2015-08-28 21:44:17
【问题描述】:

我试图使用手机 8.1 运行时中的设置弹出来为应用程序生成设置屏幕。但是编译器抛出错误,我不知道为什么。这在手机 8.0 中可以正常工作,但在 8.1 运行时似乎不行。

<SettingsFlyout
x:Class="popcornpk.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:popcornpk"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
IconSource="Assets/SmallLogo.png"
Title="CustomSetting"   >

<!-- This StackPanel acts as a root panel for vertical layout of the content sections -->
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >

    <!-- Toggle switch -->
    <StackPanel >
        <TextBlock Text="Toggle Switch" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Margin="0,0,0,25" Text="Use toggle switches to let users set Boolean values." Style="{StaticResource BodyTextBlockStyle}"/>
        <ToggleSwitch Margin="-6,0,0,0" Header = "Download updates automatically" HorizontalAlignment="Left" HorizontalContentAlignment="Left"/>
        <ToggleSwitch Margin="-6,0,0,0" Header = "Install updates automatically" HorizontalAlignment="Stretch"/>
    </StackPanel>

    <!-- Button -->
    <StackPanel >
        <TextBlock Text="Push button" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Text="Button label" Style="{StaticResource BodyTextBlockStyle}"/>
        <Button Margin="-3,0,0,0" Content="Clear"/>
        <TextBlock Margin="0,0,0,25" Text="With a push button, users initiate an immediate action." Style="{StaticResource BodyTextBlockStyle}"/>
    </StackPanel>

    <!-- ComboBox -->
    <StackPanel >
        <TextBlock Text="ComboBox" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Margin="0,0,0,25" Text="Use the ComboBox to allow users to select one item from a set of text-only items." Style="{StaticResource BodyTextBlockStyle}"/>
        <ComboBox Header="State:" Margin="0,7,0,0" SelectedIndex="0" HorizontalAlignment="Left">
            <ComboBoxItem Content="Washington"/>
            <ComboBoxItem Content="Oregon"/>
            <ComboBoxItem Content="California"/>
        </ComboBox>
    </StackPanel>

    <!-- HyperlinkButton -->
    <StackPanel >
        <TextBlock Text="Hyperlink" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Margin="0,0,0,25" Text="Use a hyperlink when the associated action will take the user out of this flyout." Style="{StaticResource BodyTextBlockStyle}"/>
        <HyperlinkButton Padding="-5,0,0,0" Content="View privacy statement" Tag="http://privacy.microsoft.com" HorizontalAlignment="Left"/>
    </StackPanel>

    <!-- TextBox -->
    <StackPanel >
        <TextBlock Text="TextBox" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Margin="0,0,0,25" Text="Use a TextBox to allow users to enter text." Style="{StaticResource BodyTextBlockStyle}"/>
        <StackPanel Margin="0,7,0,0" Orientation="Horizontal">
            <TextBox HorizontalAlignment="Left" Width="150"/>
            <Button Margin="20,0,0,0" Content="Add"/>
        </StackPanel>
    </StackPanel>

    <!-- RadioButton -->
    <StackPanel>
        <TextBlock Text="Radio button group" Style="{StaticResource TitleTextBlockStyle}"/>
        <TextBlock Margin="0,0,0,25" Text="Lets users choose one item from a small set of mutually exclusive, related options." Style="{StaticResource BodyTextBlockStyle}"/>
        <TextBlock Text="Video quality" Style="{StaticResource BodyTextBlockStyle}"/>
        <RadioButton Margin="0,7,0,0" Content="High"/>
        <RadioButton Margin="0,17,0,0" Content="Medium"/>
        <RadioButton Margin="0,17,0,0" Content="Low"/>
    </StackPanel>
</StackPanel>

严重性代码描述项目文件行 错误 CS0263“设置”的部分声明不得指定不同的基类 popcornpk C:\Users\david\Documents\Visual Studio 2015\81StoreLiveAppsPhoneOnlyLIVE\popcornpk\popcornpkhub\popcornpk\popcornpk\obj\Debug\Settings.g.i.cs 15

我的基类和其他页面一样 注意 2

公共部分类设置:页面

我将上面的设置更改为设置,但它已编译,但浮标没有工作或弹出,所以它不知道为什么它没有。

注意 2 为了避免混淆,我不想要一个基本页面,我希望能够使用属于 8.0 的 settingsflyout 显然微软已经为 8.1 UAP 做出了这样的解释

【问题讨论】:

  • 尝试像这样启动您的 XAML:&lt;Page ...&gt; 而不是 &lt;SettingsFlyout ..&gt;
  • 这是一个设置弹出 romaz 请参阅 msdn 上的文档,它不是按照 msdn 以页面开头的
  • 如果你想在后面的代码中有一个基类Page,xaml 部分必须和Will has explained in his answer有相同的基类。
  • 我不想让一个基类页面正确阅读问题它的设置弹出窗口我试图在 8.1 运行时中实现不是页面,因为我不需要他们的内容,但我发现我需要设置他们,但它仍然没有显示设置弹出窗口!
  • 那么这个'flyout'是如何实现的呢? (页面,弹出窗口,其他?)你如何调用它? (导航、显示、其他?)您的问题似乎缺少最相关的信息。

标签: c# xaml windows-phone-8.1


【解决方案1】:

这个例外告诉你你需要知道的一切。

查看您的 xaml。这是文件的前两行:

<SettingsFlyout
    x:Class="popcornpk.Settings"

这表示您要声明一个名为 popcornpk.Settings 的新类(顺便说一句,命名空间应该是 PascalCased),它扩展了基类 SettingsFlyout

当您将新的 xaml 文件添加到应用程序时,它实际上会创建三个文件 - .xaml 文件、您编辑的 .xaml.cs 文件和包含设计器生成的代码的神秘临时 .g.i.cs 文件(例如InitializeComponent()的实现)。

.xaml.cs 和 .g.i.cs 文件是部分类文件,由编译器合并。请注意异常消息的内容--

“设置”的部分声明不得指定不同的基类

这些不同的基类是什么?

嗯,从 xaml 中,我们可以看到第一个——SettingsFlyout

来自你的 sn-p,

公共部分类设置:页面

我们看到了另一个基类——Page

不知道你是怎么搞砸的,但简单的解决方法是从 .xaml.cs 文件中删除基类声明:

public partial class Settings
{
    // snip

【讨论】:

  • 如果你看一下我的笔记,我已经完成了这个并进行了调整,但设置仍然没有显示它必须从 8.1 运行时中删除
【解决方案2】:

除了Will has said about partial classes,肯定会解决这个错误,你可能无法在电话上使用SettingsFlyout - 按照以下说明:

注意 SettingsFlyout 仅支持与 Windows 8 中的 SettingsPane 一起使用。虽然 SettingsFlyout 类型在 Windows Phone 项目中可见,但 SettingsPane 在 Windows Phone 上不存在,因此不支持使用 SettingsFlyout。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 2011-03-19
    • 1970-01-01
    相关资源
    最近更新 更多