Enlace de datos en el cuadro de lista Silverlight de la colección de dos listas

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. ¿Cómo hago esto?

preguntado el 08 de noviembre de 11 a las 18:11

1 Respuestas

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.

¿Cómo te sientes al respecto?

¡Gracias!

respondido 08 nov., 11:23

I agree that this would be the best approach. Or just create a new object that adds this property and create the list by combining the two other lists. - Bryant

+1: The "model" as it stands just isn't suited to the task. A "ViewModel" adaptation is warranted to make the UI implementation easier. - AnthonyWJones

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.