我的Windows手机应用程序在启动前一直崩溃,到目前为止我只完成了ui

时间:2015-01-15 20:18:27

标签: c# xaml windows-runtime windows-phone-8.1

我一直在尝试为Windows Phone 8.1制作应用程序我决定使用集线器模板。我设计了我的应用程序,现在当我尝试运行它时,每次都会抛出一个exeption。这让我非常困惑,因为我使用vs自己的控件进行了所有设计并且没有编写任何我自己的xaml。但我得到一个windows.UI.Xaml.UnhandledException任何关于这个的帮助真的很棒这是我为Windows手机制作的第一批应用之一,所以我对这个主题相当新。如果有任何用途,这是xaml。

<Page
    x:Class="AttemptAtHub.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AttemptAtHub"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ControlTemplate x:Key="HubSectionControlTemplate1" TargetType="HubSection">
            <Grid>
                <TextBox x:Name="tbHours" HorizontalAlignment="Left" Margin="8,160,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" InputScope="Number" Width="87" PlaceholderText="   hrs"/>
                <TextBox x:Name="tbMinutes" HorizontalAlignment="Left" Margin="109,160,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" InputScope="Number" PlaceholderText="   min" Width="87"/>
                <TextBlock x:Name="tblk_" HorizontalAlignment="Left" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" FontSize="21.333" Margin="101,163,0,0"/>
                <TextBlock HorizontalAlignment="Left" Margin="8,205,0,0" TextWrapping="Wrap" Text="Work date" VerticalAlignment="Top" FontSize="13.333"/>
                <DatePicker HorizontalAlignment="Left" Margin="8,216,0,0" VerticalAlignment="Top" Width="133"/>
                <AppBarButton HorizontalAlignment="Left" Icon="Add" Label="" Margin="132,213,0,0" VerticalAlignment="Top" Height="59"/>
                <TextBlock x:Name="hdrAddHours" HorizontalAlignment="Left" Margin="20,110,0,0" Style="{StaticResource ControlHeaderTextBlockStyle}" TextWrapping="Wrap" Text="Add Hours" VerticalAlignment="Top"/>
            </Grid>
        </ControlTemplate>
        <ControlTemplate x:Key="HubSectionControlTemplate2" TargetType="HubSection">
            <Grid>
                <TextBlock x:Name="hdrWage" HorizontalAlignment="Left" Margin="20,95,0,0" Style="{StaticResource ControlHeaderTextBlockStyle}" TextWrapping="Wrap" Text="Wage" VerticalAlignment="Top" Foreground="White" FontSize="18.667"/>
                <TextBlock HorizontalAlignment="Left" Margin="8,150,0,0" TextWrapping="Wrap" Text="Working hour rate" VerticalAlignment="Top" FontSize="13.333"/>
                <TextBlock HorizontalAlignment="Left" Margin="8,175,0,0" TextWrapping="Wrap" Text="$" VerticalAlignment="Top" FontSize="21.333"/>
                <TextBox x:Name="tbWage" HorizontalAlignment="Left" Margin="26,170,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" InputScope="Number" PlaceholderText="   0.00" Width="89"/>
                <AppBarButton HorizontalAlignment="Left" Icon="Add" Label="" Margin="109,159,0,0" VerticalAlignment="Top"/>
            </Grid>
        </ControlTemplate>
    </Page.Resources>

    <Grid>
        <Hub x:Name="Hub" Header="Hours+" Background="{ThemeResource PhoneAccentBrush}">
            <HubSection x:Name="sctnAddHours" Template="{StaticResource HubSectionControlTemplate1}" Header="Add Hours">
                <DataTemplate>
                    <Grid/>
                </DataTemplate>
            </HubSection>
            <HubSection x:Name="sctnExpenses" Header="AddExpenses">
                <HubSection.Resources>
                    <ControlTemplate x:Key="HubSectionControlTemplate2" TargetType="HubSection">
                        <Grid>
                            <TextBlock x:Name="hdrAddExpenses" HorizontalAlignment="Left" Margin="20,110,0,0" Style="{StaticResource ControlHeaderTextBlockStyle}" TextWrapping="Wrap" Text="Add Expenses" VerticalAlignment="Top"/>
                            <TextBlock x:Name="tblk_" HorizontalAlignment="Left" Margin="8,156,0,0" TextWrapping="Wrap" Text="$" VerticalAlignment="Top" FontSize="21.333"/>
                            <TextBox x:Name="tbExpense" HorizontalAlignment="Left" Margin="30,150,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" InputScope="Number" PlaceholderText="   0.00" Width="89"/>
                            <TextBlock HorizontalAlignment="Left" Margin="8,200,0,0" TextWrapping="Wrap" Text="Expense date" VerticalAlignment="Top" FontSize="13.333"/>
                            <DatePicker HorizontalAlignment="Left" Margin="8,215,0,0" VerticalAlignment="Top"/>
                            <TextBlock HorizontalAlignment="Left" Margin="8,270,0,0" TextWrapping="Wrap" Text="Expense date" VerticalAlignment="Top" FontSize="13.333"/>
                            <TextBox x:Name="tbNotes" HorizontalAlignment="Left" Margin="8,290,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="260"/>
                            <AppBarButton HorizontalAlignment="Left" Icon="Add" Label="" Margin="255,277,0,0" VerticalAlignment="Top"/>
                        </Grid>
                    </ControlTemplate>
                </HubSection.Resources>
                <HubSection.Template>
                    <StaticResource ResourceKey="HubSectionControlTemplate2"/>
                </HubSection.Template>
                <DataTemplate>
                    <Grid/>
                </DataTemplate>
            </HubSection>
            <HubSection x:Name="sctnWage" Header="Set wage" Height="640" Template="{StaticResource HubSectionControlTemplate2}">
                <DataTemplate>
                    <Grid/>
                </DataTemplate>
            </HubSection>
        </Hub>

    </Grid>
</Page>

再次感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您正在替换HubSection的模板。

通过设置

来设置HubSection的ControlTemplate
<HubSection Template="{...}">...</HubSection>

此模板需要具有名称&#34; WrappingTransform&#34;的CompositeTransform。在它的根元素上,Hub Control可以正常工作。

您真的只想设置HubSections子DataTemplate。

<HubSection Header="Add Hours">
    <DataTemplate>...</DataTemplate>
</HubSection>

HubSection的内容是DataTemplate可能有点令人困惑,但请记住,内容属性(也就是HubSection内部的内容)而不是模板属性(也就是HubSection本身的外观,它想要修改的边框,间距等。