0
我在为物品控件中的物品生成点击事件时遇到问题。我是xaml nad wpf的新手。你能帮我解决问题吗?下面是我已经提出的代码,但现在不知道如何为生成的项目添加单击事件。非常感谢你的回应。感谢您阅读如何将物品点击事件添加到物品控件
<ItemsControl ItemsSource="{Binding Text, Source={StaticResource TextContainer}}">
<!--text is an object bein made public from TextToDisplay. There can be many objects released ratger than one in this case-->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ItemWidth="100"
ItemHeight="100" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type sys:String}">
<Border CornerRadius="100"
Background="BlueViolet">
<Button Margin="20"
Content="{Binding}"
HorizontalContentAlignment="Center" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
您将不得不编辑您的曲目并在那里发布代码。评论代码是完全不可读的。 – goobering
也许一个'ListBox'或者已经处理过Item事件的东西会更适合你的目的,否则你可以把Button或任何你喜欢的东西放在ItemsControl中,还有其他的信息可以指向你正确的方向。 –