Border
Border是一个柜形边框,用来宣染其他控件的边缘。
下面看一段动画的代码,用代码分析。
<StackPanel Orientation="Vertical" HorizontalAlignment="Center"> <Border Background="#99FFFFFF" BorderBrush="#CCCCFF" BorderThickness="1"
Margin="0,60,0,20" Padding="20" >
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation
Storyboard.TargetProperty="BorderThickness"
Duration="0:0:1.5" FillBehavior="HoldEnd" From="1,1,1,1" To="28,14,28,14" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
<TextBlock>
This example shows how to use the ThicknessAnimation to create
an animation on the BorderThickness property of a Border.
</TextBlock>
</Border>
</StackPanel>
其中在<Border Background="#99FFFFFF" BorderBrush="#CCCCFF" BorderThickness="1" Margin="0,60,0,20" Padding="20" >中,Background是背景色;BorderBrush是边框的的颜色;BorderThickness是边框的宽度;Margin是边框的位置,在这个属性中有四个值,从前到后分别为到Border父容器(存放Border的控件,本例中是StackPanel)的左边距,上边距,右边距,下边距;Paddin是Border中填充的高度。
<Border.Triggers></Border.Triggers>标签中是一个触发的效果。从<EventTrigger RoutedEvent="Border.Loaded">可知Border的Loaded(加载)是触发点。触发了什么呢?在这里:<Storyboard> </Storyboard>之间是一个动画区。<ThicknessAnimation
Storyboard.TargetProperty="BorderThickness" Duration="0:0:1.5" FillBehavior="HoldEnd" From="1,1,1,1" To="28,14,28,14" />是要体现动画的关键所在,首先是对BorderThickness的值进行改变,Duration是持续的时间,是时分秒格式,当前值是1.5秒;FillBehavior是动画运行完的状态,它有两个值,“HoldEnd”和“Stop”,前者是保持运行完后的结果,后者是回到动画前的状态。Form和To的回个参数数是Border的左边框厚并,上边框厚度,右边框的厚度,下边框厚度。<TextBlock> This example shows how to use the ThicknessAnimation to create an animation on the BorderThickness property of a Border. </TextBlock>是Border中的内容。
再看一个例子。
Xaml文件代码:
<Border Name="root" BorderThickness="2" BorderBrush="Black" Background="LightGray" Width="350" Height="350">
<Canvas>
<Button Name="btn" Canvas.Top="40" Canvas.Left="40" Background="LightSkyBlue" Height="35" Click="ChangeBG">
Click Me to change the Background Color
</Button>
<TextBlock Canvas.Top="130" Canvas.Left="40" Name="Text1">Waiting for Click!
</TextBlock>
</Canvas>
</Border>
CS文件代码:
void ChangeBG(object sender, System.Windows.RoutedEventArgs e)
{
root.Background = System.Windows.Media.Brushes.LightSteelBlue;
btn.Content = "Clicked!";
Text1.Text = "The background is now LightSteelBlue";
}
从上面的例子不难看出,这是一个在Button的Click中调用“ChangeBG”函数。首先,本例中的Border的名字为“root”,这在CS中要调用,以及Button的名字为“btn”,TextBlock的名字为“Text1”,例子中在单击Button的事件中改变Border的北景色,及Button的内容,TextBlock的内容。
本文参考MSDN组织。
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524