[英]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.