如何查看我的 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,这给了我想要的效果(所有折叠的框,直到我们将鼠标悬停在它们上方),但我仍然想知道如何检查这样的事情..
Silverlight newbie here, so I apologize if this question isn't even worded correctly.
I am playing around with a richtextbox and storyboard animations. Basically, on mouseenter animate to 100px, on mouseleave animate to 0px.
This is fairly basic, but what I can't figure out is how to see if it is in the minimize or maximize state.
Here is the 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>
And the code Behind:
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();
}
}
}
EDIT:
Ok, I just changed the starting height of the control to 0px, which gave me the effect I was looking for (all collapsed boxes until we mouse over them), but I would still like to know how to check against things like this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是使用情节提要完成事件来让您设置状态。
例子
on solution would be to use the storyboards completed event to let you set the state.
example