从 Linq feed 在后台代码中创建数据透视

发布于 2024-11-04 05:14:21 字数 1892 浏览 0 评论 0原文

我目前有一个类,它使用 Linq to XML 获取 XML 提要并将其分派到 XAML 页面中的 ListBox。我从教程中获取了这个,并且想知道我是否能够使其出现在数据透视中?

我的想法是加载提要,并在后台代码中为每个项目创建一个数据透视页面(例如,对于我的数据中的每个项目,创建一个新的数据透视表,包含其他内容)

这可能吗? 我目前通过绑定加载并使用“TextBlock Text =“{Binding Id}”/>”将数据获取到ListBox中在 XAML 中,并在后台代码中加载提要,如下所示:

myFeed.LoadFeed(//name of the listbox that currently has to exist in XAML)

这是我的代码,用于加载 XML 提要并分派到列表框

public class FeedItem
{
    public string Id { set; get; }
    public string Text { set; get; }

}

public class Feed
{
    ListBox myContext;

    public void LoadFeed(ListBox context)
    {
        myContext = context;
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://myDataSource"));
        request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
    }


    private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
    private void ReadCallback(IAsyncResult asynchronousResult)
    {


        HttpWebRequest request =
            (HttpWebRequest)asynchronousResult.AsyncState;
        HttpWebResponse response =
          (HttpWebResponse)request.EndGetResponse(asynchronousResult);
        XDocument doc = XDocument.Load(response.GetResponseStream());

           List<FeedItem> feedItems = (from question in doc.Descendants(m + "properties")
                                        select new FeedItem()
                                        {
                                            Id = question.Descendants().ToList()[0].Value,
                                            Text = question.Descendants().ToList()[1].Value
                                        }).ToList();

            myContext.Dispatcher.BeginInvoke(() => { myContext.ItemsSource = feedItems; });






    }
}

什么可以用来保存数据,以便它可以进入数据透视表? 如何将响应逐项解析为新的枢轴?

I've currently got a class that gets and dispatches an XML feed using Linq to XML to a ListBox in my XAML page. I took this from a tutorial, and was wondering, would I be able to make it appear in a pivot?

My idea is to load the feed, and create a pivot page just in background code for each item (Something like, foreach item in my data, create a new pivot, with other content)

Is this possible?
I currently get data into a ListBox by Binding the loading and using "TextBlock Text="{Binding Id}"/>" in XAML, and loading the feed in the background code as follows:

myFeed.LoadFeed(//name of the listbox that currently has to exist in XAML)

Here is my code that loads the XML feed and dispatches to a Listbox

public class FeedItem
{
    public string Id { set; get; }
    public string Text { set; get; }

}

public class Feed
{
    ListBox myContext;

    public void LoadFeed(ListBox context)
    {
        myContext = context;
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://myDataSource"));
        request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
    }


    private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
    private void ReadCallback(IAsyncResult asynchronousResult)
    {


        HttpWebRequest request =
            (HttpWebRequest)asynchronousResult.AsyncState;
        HttpWebResponse response =
          (HttpWebResponse)request.EndGetResponse(asynchronousResult);
        XDocument doc = XDocument.Load(response.GetResponseStream());

           List<FeedItem> feedItems = (from question in doc.Descendants(m + "properties")
                                        select new FeedItem()
                                        {
                                            Id = question.Descendants().ToList()[0].Value,
                                            Text = question.Descendants().ToList()[1].Value
                                        }).ToList();

            myContext.Dispatcher.BeginInvoke(() => { myContext.ItemsSource = feedItems; });






    }
}

What can be used to hold the data so it can go in a pivot?
How do i parse the response item-by-item, into a new pivot?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-11-11 05:14:21

是的,你可以。您需要向 Pivot 控件提供数据模板。请注意在数据透视表级别定义的标题模板,而不是在数据透视项级别定义的标题模板。

<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot ItemsSource="{Binding MyPivots}">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding MyTitle}"/>
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <controls:PivotItem>                       
                <TextBlock Text="{Binding YourRssText}" />
            </controls:PivotItem>
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>

以及代码隐藏类:

public partial class MainPage : PhoneApplicationPage{
     public List<RssFeed> MyPivots { get; set; }
    // Constructor
    public MainPage()
    {
    MyPivots = new List<RssFeed>
    {
        new RssFeed{ MyTitle = "Title1", YourRssText = "Body1"},
        new RssFeed{ MyTitle = "Title2", YourRssText = "Body2"},
        new RssFeed{ MyTitle = "Title3", YourRssText = "Body3"},
    };
    InitializeComponent();
    this.DataContext = this;

     }
}


public class RssFeed   
{   
   public string MyTitle { get; set; }

   public string YourRssText { get; set; }
 }

Yes, you can. You need to provide a datatemplate to the Pivot control. Give attention to the header template which is defined at Pivote level not on the PivotItem's one.

<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot ItemsSource="{Binding MyPivots}">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding MyTitle}"/>
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
    <controls:Pivot.ItemTemplate>
        <DataTemplate>
            <controls:PivotItem>                       
                <TextBlock Text="{Binding YourRssText}" />
            </controls:PivotItem>
        </DataTemplate>
    </controls:Pivot.ItemTemplate>
</controls:Pivot>

And the code-behind class:

public partial class MainPage : PhoneApplicationPage{
     public List<RssFeed> MyPivots { get; set; }
    // Constructor
    public MainPage()
    {
    MyPivots = new List<RssFeed>
    {
        new RssFeed{ MyTitle = "Title1", YourRssText = "Body1"},
        new RssFeed{ MyTitle = "Title2", YourRssText = "Body2"},
        new RssFeed{ MyTitle = "Title3", YourRssText = "Body3"},
    };
    InitializeComponent();
    this.DataContext = this;

     }
}


public class RssFeed   
{   
   public string MyTitle { get; set; }

   public string YourRssText { get; set; }
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文