简体   繁体   English

ListBox.ItemTemplate在DataTemplate内部具有自定义控件模板

[英]ListBox.ItemTemplate with a custom control template inside DataTemplate

I'm developing a Windows Phone application. 我正在开发Windows Phone应用程序。 I have defined a ListBox.ItemTemplate's DataTemplate as follows: 我已经定义了一个ListBox.ItemTemplate的DataTemplate,如下所示:

<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. 我想将ListBoxItem内的所有内容转换为控件,因为我想向其中添加Click事件。

How can I do this? 我怎样才能做到这一点?

Thank you. 谢谢。

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. 您还应该考虑使用列表框上的“ SelectionChanged”事件,而不是在控件上单击(点击)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Listbox.ItemTemplate中找到控件(WPF C#) - Find control inside Listbox.ItemTemplate (WPF C#) 每个ListBox.ItemTemplate&gt; DataTemplate中都有不同的WPF故事板动画 - Different WPF Storyboard Animation in each ListBox.ItemTemplate>DataTemplate 如何在Windows Phone 7中以编程方式创建ListBox.Itemtemplate,datatemplate - How to create ListBox.Itemtemplate,datatemplate programatically in Windows Phone 7 如何从ListBox.ItemTemplate DataTemplate内部调用Button命令以传递参数而不选择ListBox项目? - How do I call Button command from inside of ListBox.ItemTemplate DataTemplate, to pass parameter without selecting ListBox item? ListBox.ItemTemplate内部的图像如何在点击时更改不透明度 - Image inside ListBox.ItemTemplate how to change opacity on tap 是否有一个RichTextBox等效于ListBox.ItemTemplate? - Is there a RichTextBox equivalent to a ListBox.ItemTemplate? DataTrigger在ListBox.ItemTemplate中不起作用 - DataTrigger not working within a ListBox.ItemTemplate 将属性绑定到创建的每个ListBox.ItemTemplate - Bind property to each ListBox.ItemTemplate created 如何使 ListBox.ItemTemplate 可重用/通用 - How to make a ListBox.ItemTemplate reusable/generic 带有长文本的ListBox.ItemTemplate与ListBox宽度不匹配 - ListBox.ItemTemplate with long text does not match ListBox width
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM