【问题标题】:Listbox highlight item列表框突出显示项
【发布时间】:2015-12-21 19:12:13
【问题描述】:

我想知道为什么我可以在列表框中选择一个项目,但不能在文本上选择。所以我可以选择空白区域中的项目,但是当我单击文本或图像时它没有突出显示,我想知道为什么?

<Popup IsOpen="{Binding IsChecked, ElementName=toggleButtonAdd}" x:Name="Popup" StaysOpen="False" Placement="Right">
                <Border BorderBrush="Black" BorderThickness="1" Background="Gainsboro">
                    <StackPanel Margin="5,10,5,5">
                        <TextBlock Text="Add Existing Property:"></TextBlock>
                        <ListBox BorderBrush="Black" BorderThickness="1" Background="White" Margin="5" Padding="4" Width="130"
                                 ItemsSource="{Binding Path=AvailableProperties}" ><!--SelectionChanged="Selector_OnSelectionChanged">-->
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <ListBoxItem Margin="2">
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="{Binding Icon, Converter={StaticResource ImageToSourceConverter}}" Width="12" Height="12" Margin="3" VerticalAlignment="Center"/>
                                            <TextBlock Text="{Binding Name}" VerticalAlignment="Center"></TextBlock>
                                        </StackPanel>
                                    </ListBoxItem>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </Border>
            </Popup>

【问题讨论】:

    标签: wpf xaml listbox


    【解决方案1】:

    首先,ListBoxItem不用加DataTemplate

    如果您从DataTemplate 中删除ListBoxItem,则选择将按预期工作。 我真的在这里猜测,但我认为它与 ListBox 本身以及它找到其子项的方式有关。它当然与 ListBoxItem 是一个 ContentControl 的事实无关,因为将您的示例更改为 ContentControl 将解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多