0

ピボット コントロールを使用して WP8 アプリケーションを作成しました。5 つの PivotItems があり、そのうち 3 つを 3 つのリストにバインドするか、フィルター処理されたデータが異なる 1 つのリストにバインドする必要があります。これを行う方法?

XAML:

<phone:Pivot Name="PControl" Grid.Row="1" Style="{StaticResource PivotStyle}">
                <phone:PivotItem>
                    <phone:PivotItem.Header>
                        <Grid Height="80">
                            <TextBlock Text="offer" FontSize="45" Height="80" />
                        </Grid>
                    </phone:PivotItem.Header>
                    <phone:LongListSelector Margin="0,0,0,0" ItemsSource="{Binding lstOffer}">
                        <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Margin="0,0,0,17">
                                    <TextBlock Text="some binding" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource TextBlockMnuTekst}"/>
                                </StackPanel>
                            </DataTemplate>
                        </phone:LongListSelector.ItemTemplate>
                    </phone:LongListSelector>
                </phone:PivotItem>
  </phone:Pivot>
.
.
.

<phone:PivotItem>
                    <phone:PivotItem.Header>
                        <Grid Height="80">
                            <TextBlock Text="services" FontSize="45" Height="80" />
                        </Grid>
                    </phone:PivotItem.Header>
                    <phone:LongListSelector Margin="0,0,0,0" ItemsSource="{Binding lstServices}">
                        <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Margin="0,0,0,17">
                                    <TextBlock Text="some binding" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource TextBlockMnuTekst}"/>
                                </StackPanel>
                            </DataTemplate>
                        </phone:LongListSelector.ItemTemplate>
                    </phone:LongListSelector>
                </phone:PivotItem>

C#:

public class clsPivotData
    {
        public string Name { get; set; }
        public List<clsPivotItemList> PivotItemList { get; set; }

        public clsPivotData()
        {
            PivotItemList = new List<clsPivotItemList>();
        }
    }

    public class clsPivotItemList
    {
        public string id { get; set; }
        public string ssubname { get; set; }
        public string visible { get; set; }
        public string icon { get; set; }
        public string itemType { get; set; }
        public string url { get; set; }
        public string desc { get; set; }

    }
    
    public partial class MainPage : PhoneApplicationPage
    {
        public ObservableCollection<clsPivotData> Items { get; set; }
        public static MainPage CurrentMainPage;

        public List<clsPivotData> lstOffer { get; set; }
        public List<clsPivotData> lstServices { get; set; }
        public List<clsPivotData> lstInfo { get; set; }

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            CurrentMainPage = this;

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;

            lstOffer = new List<clsPivotData>(from i in Items where i.Name == "offer" select i);
            lstServices = new List<clsPivotData>(from i in Items where i.Name == "services" select i);
            lstInfo = new List<clsPivotData>(from i in Items where i.Name == "info" select i);
.
.
.

lstOffer と lstServices で正しいデータを取得しましたが、読み込み中のデータが表示されませんでした。これは問題ではありません。TextBlock を LongListSelector (Text=some binding) からプロパティ ssubname にバインドする方法がわかりません。これは clsPivotItemList クラスのプロパティであり、List は clsPivotData クラスのプロパティです。

4

3 に答える 3

0

私はついに答えを見つけました。MainViewModel クラスに次のコードを配置します。

public ObservableCollection<clsPivotData> Items { get; set; }
        
public ObservableCollection<clsPivotData> lstOffer { get; set; }
public ObservableCollection<clsPivotData> lstServices { get; set; }
public ObservableCollection<clsPivotData> lstInfo { get; set; }

// Constructor
  public MainViewModel()
  {
    this.Items = new ObservableCollection<clsPivotData>();

    LoadData();
    lstOffer = Items.Where(o => o.Name == "offer").FirstOrDefault().PivotItems;
    lstServices = Items.Where(o => o.Name == "service").FirstOrDefault().PivotItems;
    lstInfo = Items.Where(o => o.Name == "info").FirstOrDefault().PivotItems;    }

XAML では、次のように ListBox を挿入しました。

<ListBox Margin="0,0,0,0" ItemsSource="{Binding lstOffer}">
    <ListBox.ItemTemplate>
        <DataTemplate>
             <ItemsControl>
                  <StackPanel Margin="0,0,0,17">
                       <TextBlock Text="{Binding ssubname}" TextWrapping="Wrap" Margin="12,0,12,0" Style="{StaticResource TextBlockMnuTekst30}"/>
                  </StackPanel>
              </ItemsControl>
        </DataTemplate>
   </ListBox.ItemTemplate>
  </ListBox>

.
.
.
以前のソリューションでは、lstOffer、lstServices、および lstInfo は MainVewModel ではなく MainPage にあり、MainPage の DataContext は MainViewModel ViewModel オブジェクトに設定されていました。この新しいソリューションにより、期待どおりの結果が得られます。つまり、ListBox が読み込まれます。

于 2015-10-20T19:24:13.593 に答える
0
<Grid Datacontext="{Binding lstOffer }">
<phone:LongListSelector Margin="0,0,0,0" ItemsSource="{Binding PivotItemList }">
                        <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Margin="0,0,0,17">
                                    <TextBlock Text="{Binding ssubname}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource TextBlockMnuTekst}"/>
                                </StackPanel>
                            </DataTemplate>
                        </phone:LongListSelector.ItemTemplate>
                    </phone:LongListSelector>
</Grid>
于 2015-09-25T09:42:46.820 に答える
0

これを試して<TextBlock Text="{Binding ssubname}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource TextBlockMnuTekst}"/>

于 2015-09-25T09:32:06.493 に答える