我可以在组合框的下拉列表中显示一个按钮并可单击,但无法让选定的组合框项目(下拉列表已关闭)使该按钮可单击。它总是跳过按钮单击并仅打开下拉列表。我基本上希望我设置的 Button_Click 事件处理程序在单击后被调用。这是我的示例组合框,它显示按钮,但一旦位于所选项目中就不可单击:
<ComboBox x:Name="MyCombo" Width="200" Height="30" ItemsSource="{Binding ListCombo}">
<ComboBox.Resources>
<DataTemplate DataType="{x:Type local:ComboItemClass}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=SampleText}" Width="120" />
<Button Width="20" Content="..." Click="Button_Click"/>
</StackPanel>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
在组合框中放置按钮是我们现在可以在 WPF 中实现的非常酷的功能之一,在我们停下来考虑是否应该这样做之前,我们(包括我)对此感到非常兴奋。
在组合框中放置一个按钮很容易让用户感到困惑。我建议您将 comobox 列表项中的数据绑定到组合框外部的按钮,这是您的用户所期望的。这样,您仍然可以通过从组合框中选择一个项目来更改按下按钮的最终结果。
EDIT:
如果您有足够的空间,列表框将非常适合您想做的事情。
<ListBox>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)