Well, well, this is my very first question in StackOverflow! I've been using this site since ages but I never had to ask something because I always found the answer in someone else's question lol Apparently this is not the case anymore lol.
Anyway, I'm trying to bind a list of a custom class (that is decorated to be used with the DataContext
that manages a local SQL Server CE 3.5 database - natively included in Windows Phone 7.5) to a ListPicker
control from the WPToolkit and strangely I can't see the value of the element I bound in the ListPicker
(I made sure the list is populated).
Here's the class:
[Table(Name = "Rubriques")]
class Rubrique
{
[Column(IsPrimaryKey = true, DbType = "TINYINT", CanBeNull = false)]
public Byte Id { get; set; }
[Column(DbType = "NVARCHAR(40)")]
public String Nom { get; set; }
}
Here's the DataContext
:
class IntermediaireDataContext : DataContext
{
public IntermediaireDataContext() : base("Data Source='isostore:/IntermediaireBDD.sdf';")
{
}
public Table<Rubrique> Rubriques
{
get { return this.GetTable<Rubrique>(); }
}
}
Here's the code I use to bind the list to the ListPicker
:
using (IntermediaireDataContext context = new IntermediaireDataContext())
{
rubs = (from x in context.Rubriques select x).ToList<Rubrique>(); //rubs already exists
RubListPicker.ItemsSource = rubs;
}
Here's the XAML:
<toolkit:ListPicker x:Name="RubListPicker" SelectionMode="Single" FullModeHeader="Rubriques">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Nom}" FontSize="16"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Nom}" FontSize="26" FontWeight="Bold"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
The list of Rubrique
rubs gets populated and is set as ItemsSource
to RubListPicker
and if I remove the Text="{Binding Nom}"
of the TextBlock
in the DataTemplate
I can see the name of the class MyNamespace.Rubrique
in every element in the ListPicker
.
I can't figure out what is the problem with the data binding... Any help would be greatly appreciated :)
I'm using the last version of WPToolkit 4.2012.10.30 from NuGet in Visual Studio 2012 Ultimate with the Windows Phone 8 SDK.
Thanks for taking the time to read this!
Regards,
Ali
I found the solution and it made me laugh hard lol.
I had to change de security level of my class Rubrique; When I did set it to public everything worked fine.
Actually, the ListPicker
had access to the List<Rubrique>
but could not access the value of each Rubrique
.
A good one to remember for the future: Always check the security level of your classes/attributes/methods when using external libraries.
This is my first question ever in StackOverflow and I get to answer it myself: Like A Boss :D
So the trick was to make my class public so it can be accessed by the ListPicker control from WPToolkit ;)
Cheers!