按钮在列表框数据模板中不起作用 [英] button doesnt work inside listbox datatemplate
本文介绍了按钮在列表框数据模板中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我不知道为什么我的按钮不起作用,例如,我无法单击按钮,这里出了什么问题?
Hello,I don''t know why my button doesnt work,for eg I cannot click on the button ,what is wrong here?
<ListBox x:Name="listbox"
Focusable="True"
PreviewMouseWheel="listBox_PreviewMouseWheel"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
>
</ListBox.Resources>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<local:Panel3D
Loaded="OnPanel3DLoaded"
CorX="{Binding ElementName=sliderX, Path=Value}"
CorY="{Binding ElementName=sliderY, Path=Value}"
CorZ="{Binding ElementName=sliderZ, Path=Value}"
/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Width" Value="200" />
<Setter Property="Height" Value="200" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter ContentSource="Content" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Button x:Name="my" Onclick="DoThis"></Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
推荐答案
实际上,DataTemplate用于在ItemsControl(如列表框,列表视图或组合框)中显示项目.
并将此DataTemplate应用于ContentPresenter或ContentControl.因此,ContentPresenter是用于保存DataTemplate的容器,而ItemsPresenter是用于保存ItemTemplate的容器.因此,这就是您的按钮因为仅显示而无法工作的原因.
Actually DataTemplate is used to display the items in an ItemsControl like listbox, listview or a combobox.
And this DataTemplate is applied to the ContentPresenter or ContentControl. So you a ContentPresenter is a container for holding the DataTemplate and an ItemsPresenter is a container for holding the ItemTemplate. So that''s why your button won''t work because its only getting displayed.
这篇关于按钮在列表框数据模板中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文