簡體   English   中英

WPF ItemsControl滾動條

[英]WPF ItemsControl scrollbar

使用ItemsControlCanvas上顯示項目集合。 Probelm是我無法看到我的屏幕上的所有項目(需要使用Scrollbars ),我已經檢查了這篇文章並嘗試了同樣但它不適合我, Scrollbar顯示但禁用。 我的XAML:

<Grid>
    <DockPanel>
        <ScrollViewer>
            <ItemsControl ItemsSource={Binding MyCollection}>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        ....
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </DockPanel>
</Grid>

與ListBox不同, ItemsControl默認情況下沒有ScrollViewer

擺脫外部scrollViewer並設置ItemsControl的模板以包含ScrollViewer。 另外,當你已經在Grid中包裝ItemsControl時,我沒有看到DockPanel的任何用法。

更改這樣的布局:

<Grid>
    <ItemsControl ItemsSource={Binding MyCollection}>
        <ItemsControl.Template>
            <ControlTemplate>
                <Border
                    BorderThickness="{TemplateBinding Border.BorderThickness}"
                    Padding="{TemplateBinding Control.Padding}"
                    BorderBrush="{TemplateBinding Border.BorderBrush}"
                    Background="{TemplateBinding Panel.Background}"
                    SnapsToDevicePixels="True">
                    <ScrollViewer
                        Padding="{TemplateBinding Control.Padding}"
                        Focusable="False">
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding 
                                               UIElement.SnapsToDevicePixels}"/>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                ....
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM