รายการ WPF WrapPanel จะไม่เลื่อนทีละรายการ

ได้โปรดมีคนช่วยฉันด้วย

ฉันตั้งค่า WrapPanel ใน ListBox ItemsPanelTemplate นอกจากนี้ ฉันได้ตั้งค่า ScrollViewer.CanContentScroll="True" แล้ว

แต่เหตุใดรายการกล่องรายการจึงไม่เลื่อนขึ้น/ลงทีละรายการทีละรายการ รูปแบบการเลื่อนยังคงเป็นแบบ PIXEL

ใครสามารถช่วยฉันได้บ้าง?

<Grid>
    <ListBox x:Name="testListbox" ScrollViewer.CanContentScroll="True">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Width="200" ScrollViewer.CanContentScroll="True"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>


        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

    </ListBox>

</Grid>

person Jayho    schedule 21.10.2009    source แหล่งที่มา


คำตอบ (2)


Wrappanel ไม่ได้รับการออกแบบโดยคำนึงถึงคุณลักษณะนี้ (การเลื่อนแบบลอจิคัล) คุณจะต้องสร้างออบเจ็กต์พาเนลใหม่ที่ได้มาจากคลาส wrappanel จากนั้นใช้อินเทอร์เฟซ IScrollInfo เพื่อให้ได้ผลลัพธ์ที่คุณต้องการ

person Albert Oldfield    schedule 19.11.2009

ฉันคิดว่าฉันอาจช่วยได้ แม้ว่าฉันจะไม่แน่ใจว่าคุณพยายามบรรลุผลอะไรก็ตาม คุณช่วยเจาะจงกว่านี้ได้ไหม คุณกำลังพยายามให้ ListBoxItem แต่ละรายการมีความสามารถในการเลื่อน - สำหรับเนื้อหาหรือไม่

เนื่องจากคุณไม่สามารถเพิ่ม ScrollViewer ลงใน ItemPanelTemplate ได้ คุณได้พิจารณาเพิ่มหนึ่งรายการลงใน ListBoxItems แต่ละรายการแล้ว:

ตัวอย่าง:

<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
                <ScrollViewer>
                    <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> 
                </ScrollViewer>
            </ListBoxItem>

หากต้องการความช่วยเหลือเพิ่มเติมเกี่ยวกับ wpf/xaml ฉันพบว่าไซต์นี้ค่อนข้างดี: www.YourCodeFactory.com

person codeB10    schedule 21.10.2009
comment
ขอบคุณ codeB10 ฉันต้องการบรรลุความสามารถในการเลื่อนกล่องรายการที่เลื่อนรายการรูปภาพทีละรายการ นั่นหมายความว่าฉันสามารถเลื่อนรายการกล่องรายการทีละแถวแทนที่จะเลื่อนทีละพิกเซลได้อย่างราบรื่น คุณสามารถลองมาร์กอัปบล็อก ‹ListBox.ItemsPanel› ในโค้ดด้านบนแล้วลองเลื่อนตามรายการ เป็นเรื่องแปลกที่กล่องรายการไม่เลื่อนตามรายการเมื่อฉันเพิ่มบล็อก wrappanel - person Jayho; 22.10.2009
comment
สวัสดี - ฉันอยากจะช่วยจริงๆ แต่ฉันยังไม่แน่ใจว่าคุณกำลังพยายามทำอะไรให้สำเร็จ หากคุณต้องการเลื่อนทีละแถว - ไม่จำเป็นต้องใช้แผงปิดทับ แต่ถ้าคุณต้องการเติมรูปภาพในแต่ละรายการด้วยจำนวนรูปภาพที่ไม่ได้กำหนด ฉันคิดว่าการตั้งค่า listview ไม่ถูกต้อง ไม่ว่าจะด้วยวิธีใด โปรดชี้แจงว่าคุณยังคงต้องการวิธีแก้ไขหรือไม่ นอกจากนี้ไม่แน่ใจว่าคุณหมายถึงอะไรทีละพิกเซล คุณหมายถึงอะไรกันแน่? - person codeB10; 22.10.2009