VansFannel
VansFannel

Reputation: 45921

ListBox.ItemTemplate with a custom control template inside DataTemplate

I'm developing a Windows Phone application. I have defined a ListBox.ItemTemplate's DataTemplate as follows:

<ListBox Margin="10,10,8,8" x:Name="ChoicesList">
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel />
    </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
  <ListBox.ItemTemplate>
    <DataTemplate>
      <Grid x:Name="ListBoxItemLayout" Background="Transparent" Margin="10">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="0.281*"/>
          <ColumnDefinition Width="0.719*"/>
        </Grid.ColumnDefinitions>
        <Image Source="{Binding ImagePath}" Height="100"/>
        <StackPanel Margin="5,0,0,0" Grid.Column="1">
          <TextBlock x:Name="Name" TextWrapping="Wrap" Text="{Binding Name}" Style="{StaticResource PhoneTextTitle3Style}"/>
          <TextBlock x:Name="Description" Margin="0,5,0,0" TextWrapping="Wrap" Text="{Binding Description}" d:LayoutOverrides="Width" Style="{StaticResource PhoneTextSmallStyle}"/>
          <TextBlock x:Name="Rating" TextWrapping="Wrap" Text="{Binding Rating}" />
        </StackPanel>
      </Grid>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

I want to convert all the content inside the ListBoxItem as a Control because I want to add a Click event to it.

How can I do this?

Thank you.

Upvotes: 1

Views: 3258

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65556

In blend you can just use the "Make into Control" option.

You should also consider using the "SelectionChanged" event on the listbox, rather than a click (tap) on the control.

Upvotes: 1

Related Questions