1

我正在尝试应用 aDataTrigger来更改DataTemplatefor aListBox并收到错误消息:

"Error 1 Cannot find the Trigger target 'IssueListBox'. (The target must appear before any Setters, Triggers, or Conditions that use it.)"

我有一个ListBox主要Window的(在一个DockPanel与其他控件一起):

<ListBox x:Name="IssueListBox"
  ItemsSource="{Binding}"
    ItemTemplate="{StaticResource ShowIssueSimple}" 
    IsSynchronizedWithCurrentItem="True"
    HorizontalContentAlignment="Stretch" 
    BorderThickness="3" DockPanel.Dock="Top" 
    VerticalContentAlignment="Stretch" Margin="2"/>

DataTemplate我在 App.xaml 中有一对s,DataTrigger在第二个模板的底部有一个:

    <DataTemplate x:Key="ShowIssueDetail">
        <Border CornerRadius="4, 8, 4, 8" Margin="2" MinWidth="400" BorderThickness="3" 
                BorderBrush="{Binding Path=IssUrgency, Converter={StaticResource IntToRYGBBoarderBrushConverter}}">
            <StackPanel Orientation="Horizontal">
                 <StackPanel Margin="10">
                    <TextBlock Text="{Binding IssSubject}" FontWeight="Bold" FontSize="14"/>
                    <StackPanel Width="Auto" Orientation="Horizontal">
                        <TextBlock Text="Due: " FontWeight="Bold"/>
                        <TextBlock Text="{Binding IssDueDate}" FontStyle="Italic" HorizontalAlignment="Left"/>
                    </StackPanel>
                    <StackPanel Width="Auto" Orientation="Horizontal">
                        <TextBlock Text="Category: " FontWeight="Bold"/>
                        <TextBlock Text="{Binding IssCategory}"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="ShowIssueSimple">

        <Border CornerRadius="6" 
                Margin="2,1,2,1"
                MinWidth="400"
                BorderThickness="2" 
                SnapsToDevicePixels="True"
                BorderBrush="{Binding Path=IssUrgency, Converter={StaticResource IntToRYGBBoarderBrushConverter}}">
            <StackPanel Margin="5">
                <TextBlock Text="{Binding IssSubject}" FontWeight="Bold" FontSize="14"/>
            </StackPanel>
        </Border>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Source={StaticResource sbvm}, Path=ShowDetailListItems}" Value="True">
                <Setter TargetName="IssueListBox" Property="ItemTemplate" Value="{StaticResource ShowIssueDetail}"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

我怎样才能Trigger开始工作?谷歌先生让我失望了,很多这样的例子比比皆是,但它们不是基于另一个控制。

4

1 回答 1

3

您的数据模板是 app.xaml 中定义的 StaticResource,您正在尝试将元素名称绑定到同一范围内不存在的元素 IssueListBox。即便如此,你想要做的就是这个。Listbox 有一个数据模板 DT,在 DT 内,您尝试返回 List 框并将其 DataTemplate 设置为另一个(不是 DT)。

为什么不组合模板,将详细信息的可见性设置为折叠并根据您的属性触发可见性。那么您根本不必引用列表框,模板保持不变,当您想查看详细信息时,它只是在内部发生变化。

于 2010-01-13T04:14:29.780 回答