【问题标题】:Listbox selected item from usercontrol列表框从用户控件中选择的项目
【发布时间】:2012-01-25 13:53:11
【问题描述】:

我有一个列表框填充控件,控件填充文本框和组合框。当我编辑文本框并在组合中选择时,我需要选择基础列表项。似乎找不到解决方案。有人吗?

    <ListBox.ItemTemplate>
        <DataTemplate>
            <Controls:ComponentEditItem Background="Transparent"/>
        </DataTemplate>
    </ListBox.ItemTemplate>

【问题讨论】:

    标签: wpf select listbox highlight


    【解决方案1】:

    您可以添加一个EventTrigger,当其中一个控件获得焦点时,它会选择底层ListBoxItem。像这样的:

    <ListBox.ItemTemplate>
        <DataTemplate>
            <Controls:ComponentEditItem Background="Transparent">
                 <Controls:ComponentEditItem.Triggers>
                      <EventTrigger RoutedEvent="GotFocus">
                            <BeginStoryboard>
                                <Storyboard>
                                     <BooleanAnimationUsingKeyFrames Duration="00:00:00" Storyboard.Target="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Storyboard.TargetProperty="IsSelected">
                                          <DiscreteBooleanKeyFrame Value="True" />
                                     </BooleanAnimationUsingKeyFrames>
                                 </Storyboard>
                            </BeginStoryboard>
                       </EventTrigger>
                 </Controls:ComponentEditItem.Triggers>
           </Controls:ComponentEditItem>
        </DataTemplate>
    </ListBox.ItemTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多