0

クラスのインスタンスを C# の ListBox にバインドしようとしています。

私の MainPage.xaml.cs で

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (fan == null)
                fan = (Fanfou)e.Parameter;

            RefreshHomeTimeLine(fan.oauth_token, fan.oauth_token_secret);

        }

        private async void RefreshHomeTimeLine(string access, string access_secret)
        {
            string text=await fan.getFanfouApi("http://api.fanfou.com/statuses/home_timeline.json", access, access_secret);
            fanfouHomeTL = JsonConvert.DeserializeObject<FanfouHTL>(text);
        }

fanfouHomeTL は良好で、ステータスのコレクションが含まれていました。

そのクラスの宣言は次のとおりです。

public class FanfouHTL
{
    private ObservableCollection<Status> statuses;

    public ObservableCollection<Status> Statuses
    {
        get
        {
            return statuses;
        }
        set
        {
            statuses = value;
        }
    }

}

今、私はそのインスタンスをListBox(グリッド内の) にバインドしようとしていますMainPage.xaml。私はすでにそのために作成ItemTemplateしましたListBoxDataContextグリッドの をFanfouHTL(クラス)に入れると、には何も表示されないようListBoxです。DC をfanfouHomeTL(インスタンス)に設定すると、でMainPage失敗しInitializeComponentます。

どんなヒントでも大歓迎です。

4

1 に答える 1

0

インスタンスを初期化していますか? FanfouHTL のパブリック プロパティ インスタンスを作成し、リスト ボックスのデータ コンテキストをコントロールに設定してから、プロパティのコレクションにバインドしてみてください。

public FanfouHTL Foobar {get;private set;}
//...snip...

public MyComponent(){
  Foobar = new FanfouHTL();
  InitialiseComponent();
}

次に、XAML で

<UserControl x:Name="MyComponent" DataContext="{Binding RelativePath=Self}">
<!--(can't remember exact syntax here off the top of my head, but run with it)-->
    <ListBox ItemSource="{Binding Path=Foobar.Statuses}" />
</UserControl>
于 2013-01-25T14:46:18.923 に答える