Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何使用ControlTemplate.Triggers、ControlTemplate.TargetType以及使用键盘快捷键访问ControlTemplate中的控件_Wpf_Triggers_Keyboard Shortcuts_Controltemplate_Expander - Fatal编程技术网

Wpf 如何使用ControlTemplate.Triggers、ControlTemplate.TargetType以及使用键盘快捷键访问ControlTemplate中的控件

Wpf 如何使用ControlTemplate.Triggers、ControlTemplate.TargetType以及使用键盘快捷键访问ControlTemplate中的控件,wpf,triggers,keyboard-shortcuts,controltemplate,expander,Wpf,Triggers,Keyboard Shortcuts,Controltemplate,Expander,我有一个带有LlistBox的用户控件,它有一个带有Collectionview的ItemsSource。为了分组,我使用了分组样式,其中分组的项目将位于Expander控件中,如下所示 我希望标签内容为“未知”的expander在默认情况下必须关闭,其余部分应保持打开状态,因此我尝试了两种方法,但均无效 在Controltemplate.Triggers中使用数据触发器 在Controltemplate.Resources中使用数据触发器 由于扩展器计数的数量因组而异,是否可以使用快捷键打开和

我有一个带有
LlistBox
的用户控件,它有一个带有Collectionview的
ItemsSource
。为了分组,我使用了分组样式,其中分组的项目将位于
Expander
控件中,如下所示

我希望标签内容为“未知”的
expander
在默认情况下必须关闭,其余部分应保持打开状态,因此我尝试了两种方法,但均无效

  • 在Controltemplate.Triggers中使用数据触发器
  • 在Controltemplate.Resources中使用数据触发器
  • 由于扩展器计数的数量因组而异,是否可以使用快捷键打开和关闭扩展器??

    例如:如果我有两个扩展器(动物/鸟类),使用Alt+F1我需要关闭或打开“Exapnder Animals”

    使用Alt+F2我需要关闭或打开“Exapnder Birds”


    如下修改数据触发器:

    <ControlTemplate.Triggers>
       <DataTrigger Binding="{Binding ElementName=lbl, Path=Content}" Value="UNKNOWN">
          <Setter TargetName="exp" Property="IsExpanded" Value="False" />
       </DataTrigger>
    </ControlTemplate.Triggers>
    
    
    
    并将扩展器命名为:

    <Expander x:Name="exp" IsExpanded="True" FlowDirection="LeftToRight">
    ...
    
    
    ...
    
    注意:必须在触发器之前定义扩展器:

    <ControlTemplate TargetType="{x:Type GroupItem}">    
       <Expander ...
       <ControlTemplate.Triggers> ...
    </ControlTemplate>
    
    
    
    真的thanx我用BooleanConverter做了一些变通方法,oops thanx很多,如果我想通过键盘快捷键打开/关闭动态生成的扩展器,customRouted命令是Approach?的一种常规方法。我的DataTrigger有什么问题。?为什么这个
    不起作用
    <ControlTemplate TargetType="{x:Type GroupItem}">    
       <Expander ...
       <ControlTemplate.Triggers> ...
    </ControlTemplate>