如何查看我的silverlight控件是“最小化”还是“最大化”

时间:2012-02-11 07:06:05

标签: silverlight state

Silverlight新手在这里,所以如果这个问题的措辞不正确,我道歉。

我正在玩富文本框和故事板动画。基本上,在mouseenter上动画为100px,在mouseleave上动画为0px。

这是相当基本的,但我无法弄清楚如何查看它是否处于最小化或最大化状态。

这是XAML:

<UserControl x:Class="AnotherTester.MainPage"
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="300" d:DesignWidth="400">
<UserControl.Resources>
    <Storyboard x:Name="Shrink">
        <DoubleAnimation Storyboard.TargetName="textBox" 
            Storyboard.TargetProperty="Height"
            From="100" To="0" Duration="00:00:00.5" />
    </Storyboard>
    <Storyboard x:Name="Grow">
        <DoubleAnimation Storyboard.TargetName="textBox" 
            Storyboard.TargetProperty="Height"
            From="0" To="100" Duration="00:00:00.5" />
    </Storyboard>
</UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Width="100">
        <Rectangle x:Name="rectangle" Fill="#FF0202F9" Height="20" Stroke="Black" Width="100" MouseEnter="rectangle_MouseEnter" MouseLeave="rectangle_MouseLeave" />
        <RichTextBox x:Name="textBox" Height="100">
            <Paragraph><Run Text="This"/></Paragraph>
            <Paragraph><Run Text="is"/></Paragraph>
            <Paragraph><Run Text="some"/></Paragraph>
            <Paragraph><Run Text="awesome"/></Paragraph>
            <Paragraph><Run Text="text"/></Paragraph>
        </RichTextBox>
    </StackPanel>

</Grid>

代码背后:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AnotherTester
{
public partial class MainPage : UserControl
{

    public MainPage()
    {
        InitializeComponent();
    }

    private void rectangle_MouseEnter(object sender, MouseEventArgs e)
    {
        Grow.Begin();
    }

    private void rectangle_MouseLeave(object sender, MouseEventArgs e)
    {    
        Shrink.Begin();
    }
}
}

编辑: 好吧,我只是将控件的起始高度更改为0px,这给了我正在寻找的效果(所有折叠的盒子,直到我们将鼠标悬停在它们上面),但我仍然想知道如何检查这样的事情..

1 个答案:

答案 0 :(得分:0)

解决方案是使用storyboards completed事件让你设置状态。

例如

Grow.Completed += (o,e) => _isCollapsed = true;