silverlight创建新的控件——一个简单的弹出菜单

照旧,直接贴代码

<UserControl
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"
x:Class
="ControlTemplate.ShowMenu"
d:DesignWidth
="200" d:DesignHeight="480">

<Grid x:Name="LayoutRoot">
<Grid.Resources>
<Storyboard x:Name="hide">
<DoubleAnimation Duration="00:00:01" From="0" To="-190" 
                                 Storyboard.TargetName="tt" Storyboard.TargetProperty="X"/>
            </Storyboard>
<Storyboard x:Name="show">
<DoubleAnimation Duration="00:00:01" From="-190" To="0" 
                                 Storyboard.TargetName="tt" Storyboard.TargetProperty="X"/>
</Storyboard>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0">
<TextBlock Text="模拟" HorizontalAlignment="Center" Margin="0,10,0,0"/>
<TextBlock Text="预警" HorizontalAlignment="Center" Margin="0,10,0,0"/>
<TextBlock Text="预报" HorizontalAlignment="Center" Margin="0,10,0,0"/>
<TextBlock Text="统计" HorizontalAlignment="Center" Margin="0,10,0,0"/>
</StackPanel>

<Rectangle Grid.Column="1" Fill="BlueViolet" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"/>

<Grid.RenderTransform>
<TranslateTransform x:Name="tt" X="0"/>
</Grid.RenderTransform>
</Grid>
</UserControl>

   ShowMenu.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ControlTemplate
{
public partial class ShowMenu : UserControl
{
private bool isShow = true;
public ShowMenu()
{
// 为初始化变量所必需
InitializeComponent();
}

private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (isShow)
{
hide.Begin();
}
else
{
show.Begin();
}
isShow = !isShow;
}
}
}

  

很简单吧

转载于:https://www.cnblogs.com/ahalc/archive/2011/07/17/2108695.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值