ListBox.ItemTemplate with a custom control template inside DataTemplate

↘锁芯ラ 提交于 2019-12-13 00:25:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3408046/listbox-itemtemplate-with-a-custom-control-template-inside-datatemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!