1

我真的不知道我的代码发生了什么。你能检查一下吗?我得到那个错误:无法解析引用程序集。请检查参考程序集。你调用的对象是空的。

MainPage.xaml:

<phone:PhoneApplicationPage
x:Class="PhoneApp2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"
                Orientation="Vertical">
        <CheckBox Name="cb1" Content="Running" 
                  Checked="cb1_Checked" Unchecked="cb1_Unchecked" />
        <CheckBox Name="cb2" Content="Biking"
                  Checked="cb2_Checked" Unchecked="cb2_Unchecked" />
        <CheckBox Name="cb3" Content="Swimming" />
        <CheckBox Name="cb4" Content="Free weights" />
    </StackPanel>
</Grid>

主页.xaml.vb

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Controls

Namespace PhoneApp2
Partial Public Class MainPage
    Inherits PhoneApplicationPage
    Private cbStates As List(Of Boolean)
    ' Constructor
    Public Sub New()
        InitializeComponent()
        cbStates = New List(Of Boolean)()
    End Sub

    Protected Overrides Sub OnNavigatedTo(e As System.Windows.Navigation.NavigationEventArgs)
        MyBase.OnNavigatedTo(e)
        cbStates = DB.readStates()
        If cbStates.Count > 0 Then
            cb1.IsChecked = cbStates(0)
            cb2.IsChecked = cbStates(1)
            cb3.IsChecked = cbStates(2)
            cb4.IsChecked = cbStates(3)
        Else
            If cb1.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb2.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb3.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb4.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
        End If
    End Sub

    Protected Overrides Sub OnNavigatedFrom(e As System.Windows.Navigation.NavigationEventArgs)
        MyBase.OnNavigatedFrom(e)
        DB.saveStates(cbStates)
    End Sub

    Private Sub cb1_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(0) = True
        End If
    End Sub

    Private Sub cb1_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(0) = False
        End If
    End Sub

    Private Sub cb2_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(1) = True
        End If
    End Sub

    Private Sub cb2_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(1) = False
        End If
    End Sub
End Class
End Namespace
4

0 回答 0