Question

In expression blend I created a sample data source in visual editor. In case of using a listbox I simply drag the collection there and data is automatically shown.

Now, I am interested to retrieve data from datasource from code behind. Is this possible?

Was it helpful?

Solution

There are a couple ways to do this, I will give you the simplest. I have a ListPicker that is bascially the same as a ListBox: Here is my ListPicker markup: Also here is a link

  <toolkit:ListPicker  Name="lpDrag" Grid.Row="4" Grid.Column="1" Loaded="lptest_Loaded"            SelectedIndex="0">
                <toolkit:ListPicker.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding name}"  />
                        </StackPanel>
                    </DataTemplate>
                </toolkit:ListPicker.ItemTemplate>
                <toolkit:ListPicker.FullModeItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" ></ColumnDefinition>
                                <ColumnDefinition ></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <TextBlock Text="{Binding name}" FontSize="26" Grid.Column="0" Grid.Row="0"/>
                            <TextBlock Text="{Binding desc}"  TextWrapping="Wrap" FontSize="26" Grid.Column="1" Grid.Row="0"  />

                        </Grid>
                    </DataTemplate>
                </toolkit:ListPicker.FullModeItemTemplate>
            </toolkit:ListPicker>

Here is the code behind:

 lpDrag.ItemsSource = //Whatever your datasource is
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top