0

私は2つのテーブルを持っています。元のページのリストボックスを形成するオンライン サービスの表 1。2 番目のテーブルは内部 DB にあり、table1 のフィールドと同じ値を持つ一意のフィールドが含まれています。

テーブル 1 のリストボックスを使用して、テーブル 2 の詳細を別のページにロードしたいと考えています。

以下のコードは 2 ページ目のコードですが、「Items コレクションを使用する前に ItemSource を空にする必要があります」という例外がスローされ続けます。

誰かがこのコードを修正したり、これを行うためのより良い方法を提案したりできますか?

public partial class PlayerProfilePanoramaPage : PhoneApplicationPage
{
    object _SelectedPlayer;
    string _playerName;
    public CollectionViewSource viewsource { get; set; }

    public PlayerProfilePanoramaPage()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
        LoadPlayerProfile();
        LoadPlayerDetails();
    }

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = _SelectedPlayer;

    }

    private void LoadPlayerProfile()
    {
        FrameworkElement root2 = Application.Current.RootVisual as FrameworkElement;
        var currentplayer = root2.DataContext as Mens_Leaders;
        _SelectedPlayer = currentplayer;
        _playerName = currentplayer.Name;


    }

    private void LoadPlayerDetails()
    {
        ObservableCollection<PlayerProfileTable> playerProfile = new ObservableCollection<PlayerProfileTable>();


        viewsource = new CollectionViewSource();
        viewsource.Filter += PlayerProfile_Filter;
        viewsource.Source = playerProfile;
        this.PlayerPanorama.ItemsSource = viewsource.View;
    }

    void PlayerProfile_Filter(object sender, FilterEventArgs e)
    {
        if (e.Item != null)
            e.Accepted = ((PlayerProfile)e.Item).Name.Equals(_playerName);
    }
}

編集: Xaml は現在、バインディングが機能していたことをテキストにするだけです。コードで定義されているように Xaml で定義されていないデータ コンテキストとソース バインディング。以下に Xaml コードを示します。

<controls:Panorama Name="PlayerPanorama" Title="my application">

        <!--Panorama item one-->
        <controls:PanoramaItem Name="panoramaPage1" Header="item1">
            <Grid Name="Grid1">
                <StackPanel>
                    <TextBlock Height="30" Name="textBlock1" Text="{Binding PlayerName, FallbackValue=Name}" />
                    <TextBlock Height="30" Name="textBlock2" Text="{Binding Height, FallbackValue=Height}" />
                    <ScrollViewer Height="387" Name="scrollViewer1" Width="422">
                        <TextBlock Height="auto" Name="textBlock3" Text="{Binding ProfileBlurb, FallbackValue=Blurb}" />
                    </ScrollViewer> 
                </StackPanel>
            </Grid>
        </controls:PanoramaItem>
4

0 に答える 0