I want to bind the data of the listbox from the two lists collection, Here’s my scnerio
I have two list as give below
public List<TipSync.TipCategories> tipCategories;
public List<TipSync.TipCategories> TipCategories
{
get
{
return tipCategories;
}
set
{
tipCategories = value;
NotifyPropertyChanged("TipCategories");
}
}
public List<TipSync.CategorySubscribed> categorySubscribed;
public List<TipSync.CategorySunscribed> CategorySubscribed
{
get
{
return tips;
}
set
{
categorySubscribed = value;
NotifyPropertyChanged("Tips");
}
}
and I have a listbox with a textblock and a button, listbox.itemsource is set to Tipcategories
<ListBox x:Name="TipCategoriesLB" Height="449" HorizontalAlignment="Left" Margin="5,49,0,0" VerticalAlignment="Top" Width="410" SelectionChanged="TipCategoriesLB_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding CategoryName}"/>
<Button Name="SubscribeBtn" Content="" Tap="Subscribe_Tap"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now if the CategorySubscribed list contains an item with the value of TipCategory.CategoryID, I want to display “Subscribed” in the content of the button, otherwise Unsubscribed. How do I do this?
Nawaz,
Not exactly the answer you were looking for; but lemme ask you this .. Why not just add a flag to each object in the TipCategories list, that indicates whether it is subscribed or not? This could be manipulated in code for each category as the subscription/unsubscription happens. The advantage of such a technique is going to be easier data binding .. you could have the Button’s Content property be bound to this flag to make the button say one thing vs other & take appropriate action if the user clicks on it.
How do you feel about this?
Thanks!