質問

In silverlight is databinding to collection<*> allowed ? Because i did the below and nothing happens

<SilverlightToolkit:Accordion Name="ToolboxCategories" SelectionMode="ZeroOrMore">
                <SilverlightToolkit:Accordion.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"></TextBlock>
                    </DataTemplate>
                </SilverlightToolkit:Accordion.ItemTemplate>
                <SilverlightToolkit:Accordion.ContentTemplate>
                    <DataTemplate>
                        <ListBox x:Name="CategoryControls" ItemsSource="{Binding States}" BorderThickness="0">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Canvas>
                                        <TextBlock Text="{Binding Name}"></TextBlock>
                                    </Canvas>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </DataTemplate>
                </SilverlightToolkit:Accordion.ContentTemplate>
            </SilverlightToolkit:Accordion>

Where Country is class that contains States property that is of type Collection<State>

Country

Public Class Country
{
  Public Collection<State> States;

  Public string Name{get;set;}
}

State

Public Class State
{
  Public string Name{get;set;}
}

Xaml.cs

List<Country> countries = DAL.GetCountries();

ToolboxCategories.ItemSource = countries;

note: I see that the accordian header shows the country name in each accordian header, but then Listbox is not databound with states.

役に立ちましたか?

解決

Please make States as full property and this will work.

 public class Country
{
    public Collection<State> States { get; set; }

    public string Name { get; set; }
}

Because when you set the Binding internally it looks for get_Property method of the object and you didn't make state as property that is why it is not showing. I hope this will help you to get rid of this issue.

Cheers! Vinod

他のヒント

When dealing with Class that act as Data Sources for the Data Bound Controls in silverlight. It is essential you use the below code to databind sometimes

ItemsSource="{Binding States,BindsDirectlyToSource=True}"

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top