我无法访问名称“LeftButton”和“右键”来自 Listbox.triggers 的地方

发布于 2024-11-11 06:40:34 字数 1788 浏览 0 评论 0原文

<GroupBox BorderThickness="0" Grid.Row="1" Header="Members" Style="{StaticResource CenteredHeaderGroupBoxStyle}">
     <GroupBox.HeaderTemplate>
         <DataTemplate>
             <Border>
                <Grid HorizontalAlignment="Center">
                  <ToggleButton Name="LButton" Content="Members" Style="{StaticResource TabL}" />
                  <ToggleButton Name="RButton" Content="Groups" Style="{StaticResource TabR}" />
                </Grid>
              </Border>
          </DataTemplate>
     </GroupBox.HeaderTemplate>    
     <GroupItem>
      <Border>
      <ListBox Name="GroupMemberList" ItemsSource="{Binding Path=MembersoftheCase}">
           <ListBox.Triggers>
               <Trigger SourceName="LButton" Property="IsChecked" Value="True">
                    <Setter Property="ListBox.ItemsSource" Value="{Binding Path=MembersoftheCase}"/>
                    <Setter Property="ListBox.ItemTemplate" Value="{StaticResource MListTemplate}"/>
               </Trigger>
               <Trigger SourceName="RButton" Property="IsChecked" Value="True">
                    <Setter Property="ListBox.ItemsSource" Value="{Binding Path=GroupsoftheCase}"/>
                    <Setter Property="ListBox.ItemTemplate" Value="{StaticResource GListTemplate}"/>
               </Trigger>
      </ListBox.Triggers>
   </ListBox>
</Border>

我在编译时遇到异常,由于此错误,设计器未加载

属性“SourceName”不代表“触发器”的有效目标,因为未找到名为“LButton”的元素。确保目标在使用它的任何 Setter、触发器或条件之前声明。

我还尝试将触发器放在按钮本身上,将 GroupmembersList 作为目标

,然后无法找到 TargetName

F1 F1

<GroupBox BorderThickness="0" Grid.Row="1" Header="Members" Style="{StaticResource CenteredHeaderGroupBoxStyle}">
     <GroupBox.HeaderTemplate>
         <DataTemplate>
             <Border>
                <Grid HorizontalAlignment="Center">
                  <ToggleButton Name="LButton" Content="Members" Style="{StaticResource TabL}" />
                  <ToggleButton Name="RButton" Content="Groups" Style="{StaticResource TabR}" />
                </Grid>
              </Border>
          </DataTemplate>
     </GroupBox.HeaderTemplate>    
     <GroupItem>
      <Border>
      <ListBox Name="GroupMemberList" ItemsSource="{Binding Path=MembersoftheCase}">
           <ListBox.Triggers>
               <Trigger SourceName="LButton" Property="IsChecked" Value="True">
                    <Setter Property="ListBox.ItemsSource" Value="{Binding Path=MembersoftheCase}"/>
                    <Setter Property="ListBox.ItemTemplate" Value="{StaticResource MListTemplate}"/>
               </Trigger>
               <Trigger SourceName="RButton" Property="IsChecked" Value="True">
                    <Setter Property="ListBox.ItemsSource" Value="{Binding Path=GroupsoftheCase}"/>
                    <Setter Property="ListBox.ItemTemplate" Value="{StaticResource GListTemplate}"/>
               </Trigger>
      </ListBox.Triggers>
   </ListBox>
</Border>

i am Getting Exception at Compile Time the Designer is Not getting Loaded because of this Error

The property 'SourceName' does not represent a valid target for the 'Trigger' because an element named 'LButton' was not found. Make sure that the target is declared before any Setters, Triggers or Conditions that use it.

i have also tried putting the Triggers at Buttons itself making GroupmembersList as the Target

then the TargetName Could not be found is coming

F1 F1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风向决定发型 2024-11-18 06:40:34

这些对象超出了文档:

您可以将此属性设置为应用触发器集合(此触发器所属的集合)范围内的任何元素的名称。这通常是包含此触发器的模板内的命名元素。

您可以使用 x:Name 指令语法命名对象。

如果要在外来对象上触发,请使用 DataTrigger。 (使用 ListBox.Style.Triggers 而不是立即触发器。)

The objects are out of scope, from the documentation:

You can set this property to the name of any element within the scope of where the trigger collection (the collection that this Trigger is part of) is applied. This is typically a named element that is within the template that contains this Trigger.

You can name an object using the x:Name Directive syntax.

If you want to trigger on foreign objects use a DataTrigger. (Use the ListBox.Style.Triggers rather than the immediate triggers.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文