0

私はこの簡単なチュートリアルをやろうとしています.2番目の部分までです: http://msdn.microsoft.com/en-us/library/cc265158(v=vs.95).aspx

(私のコードでは、Customer を Game に置き換えただけです。

しかし、エラーが発生し続けます:名前「ゲーム」は名前空間に存在しません

"clr-namespace:GameLauncher". XML 名前空間 'clr-namespace:GameLauncher;assembly=GameLauncher、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null' の不明な型 'Games'

XAML の私のコードは次のとおりです。

<Page
x:Class="GameLauncher.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GameLauncher"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:src="clr-namespace:GameLauncher"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Grid.Resources>
        <src:Games x:Key="games"/>
    </Grid.Resources>
    <ListBox HorizontalAlignment="Left" Height="{Binding ElementName=LayoutRoot, Path=ActualHeight}" Margin="50,50,0,50" VerticalAlignment="Stretch" Width="300"/>
</Grid>

私のC#コードは次のとおりです。

namespace GameLauncher
{

public class Game
{
    public String FirstName { get; set; }
    public String LastName { get; set; }
    public String Address { get; set; }

    public Game(String firstName, String lastName, String address)
    {
        this.FirstName = firstName;
        this.LastName = lastName;
        this.Address = address;
    }

}

public class Games : ObservableCollection<Game>
{
    public Games()
    {
        Add(new Game("Michael", "Anderberg",
                "12 North Third Street, Apartment 45"));
        Add(new Game("Chris", "Ashton",
                "34 West Fifth Street, Apartment 67"));
        Add(new Game("Cassie", "Hicks",
                "56 East Seventh Street, Apartment 89"));
        Add(new Game("Guido", "Pica",
                "78 South Ninth Street, Apartment 10"));
    }

}

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }
}
}

私は何か愚かなことをしている可能性が最も高く、かなり長い間コーディングしていません。

1 秒間動作させた後、Customers から Games に変更すると、すべてが動作しなくなり、再び動作させることができませんでした。再びスクラッチ。

4

1 に答える 1

0

コード内のどこでGamesオブジェクトを作成しているのかわかりません。XAMLでそのまま使用するには、ゲッター/セッターを備えたGamesプロパティが必要です。

MainPage()内で、次のようなことを行う必要があります。

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        this.Games = new Games();    // this will execute the Games constructor 
                                     // and add the games to Games
    }

    // allows you to use 'Games' in your xaml
    public ObservableCollection<Game> Games  
    {
        get;
        set;
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }
}

わかりやすくするために、ゲームだけでなく、「AllGames」や「CurrentGame」などを使用します。

于 2013-01-03T20:08:34.500 に答える