ListBox.ItemTemplate с настраиваемым шаблоном элемента управления внутри DataTemplate

Я разрабатываю приложение для Windows Phone. Я определил DataTemplate ListBox.ItemTemplate следующим образом:

<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>

Я хочу преобразовать все содержимое внутри ListBoxItem в качестве элемента управления, потому что я хочу добавить к нему событие Click.

Как я могу это сделать?

Спасибо.


person VansFannel    schedule 04.08.2010    source источник
comment
Есть ли причина, по которой вы не можете использовать MouseLeftButtonUp в своей сетке ListBoxItemLayout?   -  person Stephan    schedule 04.08.2010
comment
Да: я новичок в разработке Silverlight.   -  person VansFannel    schedule 05.08.2010
comment
Решение (не единственное) можно найти здесь: social.msdn.microsoft.com/Forums/en-US/windowsphone7series/   -  person VansFannel    schedule 05.08.2010


Ответы (1)


В blend вы можете просто использовать опцию «Make into Control».

Вам также следует рассмотреть возможность использования события "SelectionChanged" в списке, а не щелчка (нажатия) на элементе управления.

person Matt Lacey    schedule 14.12.2010