我的 Windows Phone 应用程序在启动前不断崩溃,到目前为止我只完成了 UI



我一直在尝试为Windows Phone 8.1制作一个应用程序,我决定使用集线器模板。我已经设计了我的应用程序,现在当我尝试运行它时,每次都会抛出一个 exetion。这让我非常困惑,因为我使用自己的控件进行了所有设计,并且没有编写任何自己的 xaml。但我有一扇窗户。用户界面。Xaml.UnhandledException对此的任何帮助都非常棒,这是我为Windows Phone制作的第一批应用程序之一,所以我在这个主题上相当陌生。这是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>

再次感谢您的任何帮助。

您正在替换 HubSection 的模板。

通过设置 HubSection 本身的控件模板

<HubSection Template="{...}">...</HubSection>

此模板的根元素上需要具有名称为"包装转换"的复合转换,集线器控件才能正常工作。

您实际上只想设置 HubSections 子数据模板。

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

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

相关内容

最新更新