Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Binding XML to a DomainUpDown
3 replies. Latest Post by ilya.shmorgun on June 20, 2009.
(0)
ilya.shm...
Member
4 points
91 Posts
05-28-2009 5:04 PM |
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>
shoster
660 points
96 Posts
05-29-2009 3:18 PM |
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!
05-29-2009 4:53 PM |
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>
06-20-2009 3:28 PM |
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.