簡體   English   中英

WPF Scrollviewer 不滾動...沒有拇指,只響應鼠標滾輪

[英]WPF Scrollviewer not scrolling… No thumb, only responds to mousewheel

我有一個 WPF.Net 4 應用程序,其中包含一個按鈕,單擊該按鈕會打開一個新的 windows:

CreationWindow creationWindow = new CreationWindow();
creationWindow.Owner = this;
CreationWindow.Show();

window 顯示正常,但它包含的列表框(例如 100 個圖像作為內容的列表框項)在滾動條上沒有拇指。

這是此“CreationWindow”內容的示例

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"~
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Converters="clr-namespace:Krocr.Client.Converters"                  
    x:Class="Krocr.Client.ComparisonMode"
    Title="ComparisonMode" Height="450" Width="700">
  <Grid>
     <ListBox ItemsSource="{Binding Images}"/>
  </Grid>
</Window>

滾動條可見,但我無法與之交互。 鼠標滾輪確實滾動列表。

然而..

如果我在我的主 window 中添加一個滾動查看器,並向其中添加一些項目。 隨后的滾動查看器(在新窗口中)然后正常工作......

我根本沒有為列表框或滾動查看器更改任何 styles ......非常困惑!

幫助將不勝感激,因為它讓我發瘋。

編輯:添加了問題的屏幕截圖(由於我是新手,所以還不能發布圖片......)

http://i.stack.imgur.com/XdYSs.png

這是因為默認情況下 Grid 不限制其子控件的大小,因此 ListBox 沒有意識到它需要滾動。

最快的解決方案是用 DockPanel 替換 Grid,這約束其子控件,但如果您以后要添加更多子控件,則可能需要重新考慮!

我想到了...

這是我的主窗口中的一棵瘋狂的視覺樹。xaml,它破壞了其他一切的渲染......這是問題所在:

<Grid Background="#00E5E5E5" Margin="0,75,0,0" Grid.Row="1">
        <Viewbox x:Name="docViewBox" Margin="0">
            <Grid  Margin="5" x:Name="holdingGrid">
                <Canvas x:Name="AggLayer" Margin="0" />

                <Canvas x:Name="rectCanvas"  MouseLeftButtonDown="StartDrag" MouseLeftButtonUp="EndDrag" Background="Transparent"/>
                <ListBox x:Name="overlayCanvas" Background="#00FFFFFF"  IsHitTestVisible="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas Width="{Binding ActualWidth, ElementName=rectCanvas}" Height="{Binding ActualHeight, ElementName=rectCanvas}"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>

            </Grid>
        </Viewbox>
        <Canvas x:Name="DialogLayer" Margin="0" />
    </Grid>

有了評論,它工作正常......另外,xaml 完全打破了混合,導致隨機的瘋狂行為......

我覺得是時候優化了...感謝您的輸入:)

編輯:事實上,我需要做的就是刪除 Viewbox 並且一切正常......非常奇怪 編輯 2:罪魁禍首是帶有 canvas 項目面板的列表框,尤其是這個

<Canvas Width="{Binding ActualWidth, ElementName=rectCanvas}" Height="{Binding ActualHeight, ElementName=rectCanvas}"/>

綁定這些寬度和高度值會導致視圖框進入無限縮放循環,這會破壞其他東西。 傻我...

暫無
暫無

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

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