Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Data binding - List collection item definition error
4 replies. Latest Post by silverlightdesigner on November 9, 2009.
(0)
silverli...
Member
4 points
19 Posts
11-05-2009 2:06 AM |
Hi all,
With this simple List collection I can data bind it to TextBlocks with no problem:
stories.Add(
stories = new List<StoryInfo>();
Any ideas why this item is generating this error, I added it to my List collection the same as the other three items, Heading, Body and Image, and they all bind correctly?
Thanks for any help.
Pravinku...
Contributor
4300 points
708 Posts
11-05-2009 2:19 AM |
Hi,
Can you share the code for StoryInfo class?
Thanks,
Pravin
11-05-2009 2:40 AM |
Here is the full code:
In MainPage.xaml.cs:
{
InitializeComponent();
ImageListBox.ItemsSource = stories;
DetailsPanel.ItemsSource = stories;
TransitionDetails.ItemsSource = stories;
}
selectedStory = (StoryInfo)ImageListBox.SelectedItem;
ImageListBoxCover.Visibility = Visibility.Visible;
TransitionPanel.DataContext = selectedStory;
TransitionDetails.SelectedItem = selectedStory;
IEnumerable<DependencyObject> containers = ImageListBox.GetContainers();
FrameworkElement container = GetContainerForItem(ImageListBox, selectedStory);
GeneralTransform transform = container.TransformToVisual(MainPanel);
TransitionLeftAnimation.From = location.X;
TransitionTopAnimation.From = location.Y;
TransitionStoryboard.Begin();
In detailsPanel.xaml (where the xaml control are bound):
<StackPanel Orientation="Vertical" UseLayoutRounding="True" Margin="0" d:LayoutOverrides="HorizontalMargin" HorizontalAlignment="Left" VerticalAlignment="Top" Width="216" MinHeight="75"> <Grid> <TextBlock x:Name="DetailsHeadlineCrossFade" Foreground="White" FontFamily="Arial" FontSize="12" Margin="8,6,4,0" TextWrapping="Wrap" FontWeight="Bold" /> <TextBlock x:Name="DetailsHeadline" Text="{Binding Headline}" Foreground="White" FontFamily="Arial" FontSize="12" Margin="8,6,4,0" TextWrapping="Wrap" FontWeight="Bold" /> </Grid> <Grid Margin="0,0,0,11"> <TextBlock x:Name="DetailsBodyCrossFade" Foreground="White" FontFamily="Arial" FontSize="10.667" Margin="8,4,4,0" TextWrapping="Wrap" /> <TextBlock x:Name="DetailsBody" Text="{Binding Body}" Foreground="White" FontFamily="Arial" FontSize="10.667" LineHeight="13" Margin="8,4,8,0" TextWrapping="Wrap" /> </Grid> <Grid> <TextBlock x:Name="DetailsMedia" Text="{Binding TypeBody}" Margin="8,0,0,0" FontFamily="Arial" FontSize="10.667" Foreground="White" TextWrapping="Wrap"/> </Grid> </StackPanel>
I hope that is enough code?
Mog Lian...
All-Star
16023 points
1,553 Posts
11-09-2009 2:22 AM |
The compile error means your class "StoryInfo" doesn't have property or field called "TypeBody". You need check you StoryInfo type definiton, if "TypeBody" is needed, add the field to your class definition.
11-09-2009 10:56 AM |
Mog,
Thank you, that is exactly what the problem was, the 'TypeBody' was not defined in the StoryInfo class .cs file, which was my mistake.
Thanks for pointing that out!