开发者

Problem setting MaxHeight for Silverlight Toolkit AccordionItem

开发者 https://www.devze.com 2023-02-28 15:16 出处:网络
I\'m trying to set up an Accordion that has three items.The first two expand to pre-defined heights, and the third expands to fill all remaining space; I thought this would be easy.

I'm trying to set up an Accordion that has three items. The first two expand to pre-defined heights, and the third expands to fill all remaining space; I thought this would be easy.

Here's a dummy version of what I'm trying to do. The accordion itself has a red background, and each of the items has its own color. The first two items expand appropriately to their size, but if either item 1 or 2 is open, item 3 no longer expands to fill all remaining space, but either sizes too small, leaving a big chunk of red, or too big, shooting off the bottom of the screen, eclipsing the tiny sliver of red that should still be present.

Is this a bug?

I tried working around this by using two accordions, one with the two items with max heights, and a second accordion that would expand to fill all remaining height, but I could never manage to get the layout right, as I'm guessing is obvious to you Silverlight exper开发者_JS百科ts.

Is there any way I can accomplish this?

Here's the complete code - also, note that I tried using the Height attribute instead of MaxHeight, but that just caused the accordionItem to always be that height, regardless of whether it was expanded.

<UserControl x:Class="SilverlightApplication8.accordianDemo"
    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"
    mc:Ignorable="d"
    d:DesignHeight="400" d:DesignWidth="400"
    xmlns:sdk2="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit">
    <Grid x:Name="LayoutRoot" Background="White">
        <sdk2:Accordion SelectionMode="ZeroOrMore" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <sdk2:AccordionItem Header="Item 1" MaxHeight="150" Background="LightGoldenrodYellow">
                Hello World Row 1
            </sdk2:AccordionItem>
            <sdk2:AccordionItem Header="Item 2" MaxHeight="150" Background="LightGray">
                Hello World Row 2
            </sdk2:AccordionItem>
            <sdk2:AccordionItem Header="Item 3" Background="LightBlue">
                Hello World Row 3
            </sdk2:AccordionItem>
        </sdk2:Accordion>
    </Grid>
</UserControl>


Try setting the MaxHeight on the Content. For now you have content as a string try making it a ContentControl

    <sdk2:Accordion SelectionMode="ZeroOrMore" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <sdk2:AccordionItem Header="Item 1" Background="LightGoldenrodYellow">
            <ContentControl Content="Hello World Row 1" MaxHeight="150" />
        </sdk2:AccordionItem>
        <sdk2:AccordionItem Header="Item 2" Background="LightGray">
            <ContentControl Content="Hello World Row 2" MaxHeight="150" />
        </sdk2:AccordionItem>
        <sdk2:AccordionItem Header="Item 3" Background="LightBlue">
            <ContentControl Content="Hello World Row 3" />
        </sdk2:AccordionItem>
    </sdk2:Accordion>
0

精彩评论

暂无评论...
验证码 换一张
取 消