0

我正在使用 Silverlight 工具包中提供的 ExpanderView 控件和一些自定义模板。这一切都很好,但是当 ExpanderView 折叠时,我单击展开 ExpanderView 时项目所在的 Header 下方的区域。该项目的点击事件触发。

我怎样才能解决这个问题?我是否应该在 ExpanderView 折叠时以某种方式删除点击命令或删除 ItemPanel 并在展开时再次添加它?

<DataTemplate x:Key="CustomItemTemplate">
        <Image delay:LowProfileImageLoader.UriSource="{Binding}" Width="156" Height="95" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Tap">
                    <cmd:EventToCommand Command="{Binding Storage.ImageTapCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Image>
</DataTemplate>

<toolkit:ExpanderView Grid.Column="1" Header="{Binding}"
                  Expander="{Binding}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}"
                  ItemsSource="{Binding Files}" HeaderTemplate="{StaticResource CustomHeaderTemplate}"
                  ExpanderTemplate="{StaticResource CustomExpanderTemplate}"
                  ItemTemplate="{StaticResource CustomItemTemplate}" >
      <toolkit:ExpanderView.ItemsPanel>
             <ItemsPanelTemplate>
                    <toolkit:WrapPanel />
              </ItemsPanelTemplate>
      </toolkit:ExpanderView.ItemsPanel>
</toolkit:ExpanderView>
4

1 回答 1

2

您可以在每次 ExpanderView 展开/折叠时更改每个扩展器项的根 UIElement 的 IsHitTestVisible 属性,也可以在最初绑定 ExpanderView 之后(连接到 ExpanderView.LayoutUpdated 可以正常工作)。这是一个为我解决问题的示例:

    private void FixExpanderItemsInteractivity(ExpanderView expanderView)
    {
        foreach (var item in expanderView.Items)
        {
            ContentPresenter contentPresenter = expanderView.ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter;

            if (contentPresenter != null)
            {
                UIElement expanderItemRootElement = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
                if(expanderItemRootElement != null)
                {
                    expanderItemRootElement.IsHitTestVisible = expanderView.IsExpanded;
                }
            }
        }
    }

    private void Expander_Expanded(object sender, RoutedEventArgs e)
    {
        FixExpanderItemsInteractivity(sender as ExpanderView);
    }

    private void Expander_Collapsed(object sender, RoutedEventArgs e)
    {
        FixExpanderItemsInteractivity(sender as ExpanderView);
    }

    private void Expander_LayoutUpdated(object sender, EventArgs e)
    {
        FixExpanderItemsInteractivity(sender as ExpanderView);
    }
于 2012-10-18T17:53:43.630 回答