开发者

How to grow a listbox from 0 to the size of the grid in XAML

I want the value To="200.0" will be equal to the grid size automaticaly

<ListBox HorizontalAlignment="Stretch" Grid.Column="1"
            Margin="12,90,12,12" 
            Name="listBox1" 
            Opacity="0.6"
            VerticalAlignment="Stretch" BorderThickness="0.5" BorderBrush="White">
            <ListBox.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="listBox1"
                                             Storyboard.TargetProperty=开发者_JAVA技巧"Width"
                                             From=" 0.0" To="200.0" />
                            <DoubleAnimation Storyboard.TargetName="listBox1"
                                             Storyboard.TargetProperty="Height"
                                             From="0.0" To="200.0" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ListBox.Triggers>
        </ListBox>


try something like this:

<Grid Name="test">
    <ListBox HorizontalAlignment="Stretch" Name="listBox1" 
        VerticalAlignment="Stretch" BorderThickness="0.5" BorderBrush="Black">
        <ListBox.Triggers>
            <EventTrigger RoutedEvent="Window.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="listBox1"
                                            Storyboard.TargetProperty="Width"
                                            From="0.0" To="{Binding ElementName=test,Path=ActualWidth}" />
                        <DoubleAnimation Storyboard.TargetName="listBox1"
                                            Storyboard.TargetProperty="Height"
                                            From="0.0" To="{Binding ElementName=test,Path=ActualHeight}" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </ListBox.Triggers>
    </ListBox>
</Grid>

I used ElementName binding instead of a RelativeSource binding because I can't make RelativeSource to work. I guess because the story board is not part of the same visual/control tree as the listbox.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜