2012-02-11 76 views
0

Silverlight新手在這裏,所以我很抱歉如果這個問題沒有措辭正確。如何查看我的silverlight控件是「最小化」還是「最大化」

我玩弄richtextbox和故事板動畫。基本上,在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,這給我我正在尋找的效果(所有摺疊的盒子,直到我們將鼠標放在它們上面),但我仍然想知道如何檢查這樣的事情..

回答

0

解決方案將使用故事板完成事件讓您設置狀態。

例如

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

OOOOO,我喜歡這樣的答案!好主意,謝謝。 – ledgeJumper 2012-02-13 15:45:50

相關問題