Skip to main content

Microsoft Silverlight

Unanswered Question Binding XML to a DomainUpDownRSS Feed

(0)

ilya.shmorgun
ilya.shm...

Member

Member

4 points

91 Posts

Binding XML to a DomainUpDown

Hi,

I've got an XML which consists of several items, and each of them has a title, description and an image. I want to bind this XML to a DomainUpDown control, so I can create something similar to a CoverFlow feature.

I pull the objects from the XML like this:

 

        public class pfItemCollection
        {
            public string image { get; set; }
            public string title { get; set; }
            public string desc { get; set; }
        }
   
            XDocument xdoc = XDocument.Load("ClientBin/portfolio.xml");
            var myData = from info in xdoc.Descendants("item")
                         select new pfItemCollection
                         {
                             image = info.Element("image").Value,
                             title = info.Element("title").Value,
                             desc = info.Element("description").Value
                         };

and then set the myData collection as an ItemSource for the DomainUpDown like this:

 

            DomainUpDown.ItemsSource = myData;

 

And here's the XAML for my DomainUpDown control:

 

<inputToolkit:DomainUpDown x:Name="DomainUpDown" IsCyclic="True" Style="{StaticResource DomainUpDownStyle}" Height="Auto">
            <inputToolkit:DomainUpDown.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <Image x:Name="PfImage" Source="{Binding image}" />
                        <TextBlock x:Name="PfTitle" Text="{Binding title}" />
                        <TextBlock x:Name="PfDesc" Text="{Binding desc}" />
                    </StackPanel>
                </DataTemplate>
            </inputToolkit:DomainUpDown.ItemTemplate>
        </inputToolkit:DomainUpDown>
The problem is that my DomainUpDown comes empty and doesn't show any content. If I replace it with a ListBox, then everything works just fine. What I am doing wrong here? Please help!


---------------------------------

Microsoft Student Partner

http://thund3rcat.spaces.live.com

shoster
shoster

Member

Member

660 points

96 Posts

Microsoft

Re: Binding XML to a DomainUpDown

Hi there,

I just tried to reproduce the issue but I was unable to, at least when using static data.  The only differences between my test and yours are:

1. I don't have your xml file so I manually created the data:

private ObservableCollection<pfItemCollection> items = new ObservableCollection<pfItemCollection> { 
    new pfItemCollection { image = "image1", desc = "desc", title = "title" },
    new pfItemCollection { image = "image1", desc = "desc", title = "title1" },
    new pfItemCollection { image = "image1", desc = "desc", title = "title2" },
};

2. I don't have your style so I omitted the Style property.

Can you try using hard-coded data as well as not using your style to see if either of those make a difference?  Thanks!

---
Shawn Oster [MSFT]
Program Manager | Silverlight Toolkit
http://blog.enginefour.com

ilya.shmorgun
ilya.shm...

Member

Member

4 points

91 Posts

Re: Binding XML to a DomainUpDown

I think it should work with static data.But here's my XML so you can try testing how it works with live data.

<portfolio>
  <item>
    <image>App_data/sl.jpg</image>
    <title>Some Title</title>
    <description>Some Description</description>
  </item>
  <item>
    <image>App_data/sl.jpg</image>
    <title>Some Title 2</title>
    <description>Some Description 2</description>
  </item>
  <item>
    <image>App_data/sl.jpg</image>
    <title>Some Title 3</title>
    <description>Some Description 3</description>
  </item>
  <item>
    <image>App_data/sl.jpg</image>
    <title>Some Title 4</title>
    <description>Some Description 4</description>
  </item>
</portfolio>

It's just for testing for now. So the sl.jpg can be any image. 
As for the style I used, here the code:
 
        <!--DomainUpDown Style-->
<Style x:Name="DomainUpDownStyle" TargetType="inputToolkit:DomainUpDown">
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Trebuchet Ms" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="#FF000000" />
</Style>
  
  


---------------------------------

Microsoft Student Partner

http://thund3rcat.spaces.live.com

ilya.shmorgun
ilya.shm...

Member

Member

4 points

91 Posts

Re: Re: Binding XML to a DomainUpDown

Hi Shawn,

finally got to try out using hard coded data with the DomainUpDown and it works perfectly. As to getting the data from LinqtoXML to work, I wasn't able to achieve it no matter what I've tried. 

The TransitionControl has the same issue, where it only works with hard-coded data.

So I'm not sure if this is some kind of bug or not, but sure would be great to find some kind of a solution.


---------------------------------

Microsoft Student Partner

http://thund3rcat.spaces.live.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities