Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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 在itemstemplate周围滚动查看器拾取错误的itemstemplate_Wpf_Scrollviewer_Itemscontrol - Fatal编程技术网

Wpf 在itemstemplate周围滚动查看器拾取错误的itemstemplate

Wpf 在itemstemplate周围滚动查看器拾取错误的itemstemplate,wpf,scrollviewer,itemscontrol,Wpf,Scrollviewer,Itemscontrol,我需要一个围绕ItemsControl的scrollviewer,它的ItemsPaneltemplate依赖于IsClusterSupported属性。 如果没有ScrollViewer,ItemsControl总是显示正确的ItemsPanel,但是当我添加ScrollViewer代码时,即使IsClusterSupported=False,也会显示ClusterMapItemsPanelTemplate 这里可能出了什么问题?我已经附上下面的代码 <Grid Name="MapGri

我需要一个围绕ItemsControl的scrollviewer,它的ItemsPaneltemplate依赖于IsClusterSupported属性。 如果没有ScrollViewer,ItemsControl总是显示正确的ItemsPanel,但是当我添加ScrollViewer代码时,即使IsClusterSupported=False,也会显示ClusterMapItemsPanelTemplate

这里可能出了什么问题?我已经附上下面的代码

<Grid Name="MapGrid">
    <ScrollViewer>
        <ScrollViewer.Style>
            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="VerticalScrollBarVisibility" Value="Hidden"/>
                <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsScrollingSupported}" Value="True">
                        <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
                        <Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ScrollViewer.Style>
        <ItemsControl Name="ItemsControlInnerMap" Loaded="ItemsControlInnerMap_Loaded"
              ItemsSource="{Binding ItemsCol}" Tag="{Binding IsClusterSupported, PresentationTraceSources.TraceLevel=High}">
            <ItemsControl.Style>
                <Style TargetType="{x:Type ItemsControl}">
                    <Setter Property="ItemsPanel" Value="{StaticResource MapItemsPanelTemplate}"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsClusterSupported}" Value="True">
                            <Setter Property="ItemsPanel" Value="{StaticResource ClusterMapItemsPanelTemplate}"/>
                            <Setter Property="ItemContainerStyle" Value="{StaticResource ClusterMapGridContainerStyle}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.Style>

            <ItemsControl.ItemTemplate>
                <DataTemplate>
                  <Border>
                    <TextBlock Text="{Binding LabelTxt}"/>
                  </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

            <ItemsControl.GroupStyle>
                <GroupStyle x:Name="MyGroup">

                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Border Name="BD" BorderBrush="Black" BorderThickness="2">
                                            <ItemsPresenter Name="ClusterPresenter" Tag="{Binding Name}"/>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <DataTrigger Binding="{Binding Name, Converter={StaticResource BorderVisibilityConvertor}}" Value="false">
                                                <Setter TargetName="BD" Property="BorderBrush" Value="Transparent"/>
                                            </DataTrigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <!--http://stackoverflow.com/questions/17863271/wpf-using-grid-as-itemshost-stacking-multiple-items-in-single-cell-automatical-->
                            <Setter Property="Grid.Row" Value="{Binding Items[0].ClusterGridRow}"/>
                            <Setter Property="Grid.Column" Value="{Binding Items[0].ClusterGridColumn}"/>
                            <Setter Property="Margin" Value="5"/>
                        </Style>
                    </GroupStyle.ContainerStyle>

                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <Grid Name="ClusterMapGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                  Loaded="ClusterMapGrid_Loaded"
                                  MaxHeight="{Binding AllowedMaxHeight}" MaxWidth="{Binding AllowedMaxWidth}"
                                  MinHeight="{Binding ReqMinHeight}" MinWidth="{Binding ReqMinWidth}">
                            </Grid>ReqMinHeight
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>

                </GroupStyle>
            </ItemsControl.GroupStyle>
        </ItemsControl>
    </ScrollViewer>
</Grid>

ReqMinHeight
RDV(01/04/2016):我在这里发现了一些有趣的东西,希望能更接近解决方案,但仍然需要帮助

  • 我所有的装订都很好;我在使用和不使用scrollviewer的情况下进行了调试,并在ItemsControl中看到了正确的ItemsPanel。ItemsControl的IsGrouping属性也设置正确

  • 当我在ItemsControl周围有一个scrollviewer时,无论是否有集群,都会加载ClusterMapGrid(GroupStyle.Panel)。加载后,将不加载非群集模板(MapsItemsPanelTemplate)

  • 为了解决这个问题,我尝试将ClusterMapGrid可见性绑定到ItemsControl的IsGrouping属性,但在scrollviewer中,ClusterMapGrid会以某种方式加载,加载后非集群模板无法加载

  • 我使用snoop检查ClusterMapGrid的可见性,我可以看到它已折叠,但如果在snoop中手动将其更改为任何其他值,则会加载非集群模板,一切正常。我尝试在ClusterMapGrid_加载的事件中将可见性设置为collapsed,但也没有帮助

  • 进一步调试后,我发现ScrollViewer正在加载其中的所有项目-因此会加载ClusterMapGrid,一旦我使用Snoop更改了可见性,在非集群场景中就会卸载它


  • 问题陈述:加载ClusterMapGrid后如何卸载它,我知道这是一个非集群场景

    问题在于,ScrollViewer初始化并加载XAML中的所有内容,即使它不打算加载(例如,如果IsGrouping on Items控件为true,则应加载GroupStyle.Panel,但使用ScrollViewer,它无论如何都会被加载)

    解决方案:从XAML中注释掉GroupStyle.Panel,并将其添加为参考资料中的ItemsPanelTemplate:

        <ItemsPanelTemplate x:Key="ClusterPanelTemplate">
                    <Grid Name="ClusterMapGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"                                                                      
                          Loaded="ClusterMapGrid_Loaded"
                          MaxHeight="{Binding AllowedMaxHeight}" MaxWidth="{Binding AllowedMaxWidth}"
                          MinHeight="{Binding ReqMinHeight}" MinWidth="{Binding ReqMinWidth}"/>
       </ItemsPanelTemplate>
    

    问题是,ScrollViewer初始化并加载XAML中的所有内容,即使它不是要加载的(例如,如果IsGrouping on Items控件为true,则应加载GroupStyle.Panel,但使用ScrollViewer,它无论如何都会被加载)

    解决方案:从XAML中注释掉GroupStyle.Panel,并将其添加为参考资料中的ItemsPanelTemplate:

        <ItemsPanelTemplate x:Key="ClusterPanelTemplate">
                    <Grid Name="ClusterMapGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"                                                                      
                          Loaded="ClusterMapGrid_Loaded"
                          MaxHeight="{Binding AllowedMaxHeight}" MaxWidth="{Binding AllowedMaxWidth}"
                          MinHeight="{Binding ReqMinHeight}" MinWidth="{Binding ReqMinWidth}"/>
       </ItemsPanelTemplate>
    

    ItemsControl
    上显式设置
    DataContext
    是否有效<代码>此外,在
    输出
    窗口中查找任何绑定/应用程序错误,并更新问题以告诉我们它们是什么(如果有)。我验证(使用snoop和附加调试器)ItemsControl的标记属性是否基于IsClusterSupported值正确设置。由于某些原因,PresentationOnTraceSources.TraceLevel=High不起作用。测试时您是在调试配置还是在发布配置中运行?您是否注意到PresentationTraceSources根据构建配置的不同而有所不同?并且您可能希望将items面板数据触发器绑定到
    ItemsControlInnerMap.Tag
    ,而不是
    IsClusterSupported
    ?将
    DataContext
    显式设置在
    ItemsControl
    上是否有效<代码>此外,在
    输出
    窗口中查找任何绑定/应用程序错误,并更新问题以告诉我们它们是什么(如果有)。我验证(使用snoop和附加调试器)ItemsControl的标记属性是否基于IsClusterSupported值正确设置。由于某些原因,PresentationOnTraceSources.TraceLevel=High不起作用。测试时您是在调试配置还是在发布配置中运行?您是否注意到PresentationTraceSources根据生成配置的不同而有所不同?您可能希望将items面板数据触发器绑定到
    ItemsControlInnerMap.Tag
    ,而不是
    IsClusterSupported