示例
1、IMarkupExtension(自定义 XAML 扩展标记)
XAML/ConcatMarkupExtension.cs
using System;
using System.Net;
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;
using System.Xaml;
namespace Silverlight50.XAML
{
/// <summary>
/// 实现自定义 XAML 扩展标记,需要实现 IMarkupExtension<out T> 接口
/// 自定义 XAML 扩展标记以“Extension”结尾,XAML 书写时可以不必带“Extension”
///
/// 本例中的 ConcatMarkup 扩展标记,用于合并两个字符串
/// </summary>
public class ConcatMarkupExtension : IMarkupExtension<string>
{
public object String1 { get; set; }
public object String2 { get; set; }
/// <summary>
/// 需要实现的方法,返回 ConcatMarkup 的计算结果
/// </summary>
public string ProvideValue(IServiceProvider serviceProvider)
{
return String1.ToString() + String2.ToString();
}
}
}
XAML/IMarkupExtension.xaml
<navigation:Page x:Class="Silverlight50.XAML.IMarkupExtension"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="IMarkupExtension Page"
xmlns:local="clr-namespace:Silverlight50.XAML">
<Grid x:Name="LayoutRoot">
<!--
演示自定义的 XAML 扩展标记 ConcatMarkup,本例的结果是 wanglei
-->
<TextBlock Text="{local:ConcatMarkup String1=wang, String2=lei}" />
</Grid>
</navigation:Page>
2、SoundEffectDemo(通过 XNA 处理声音效果)
Media/SoundEffectDemo.xaml
<navigation:Page x:Class="Silverlight50.Media.SoundEffectDemo"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="SoundEffectDemo Page">
<StackPanel HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Name="lblVolume" Width="100" Text="音量" TextAlignment="Center" />
<TextBlock Name="lblPitch" Width="100" Text="高音" TextAlignment="Center" />
<TextBlock Name="lblPan" Width="100" Text="平衡" TextAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Slider Name="sliderVolume" Width="100" Height="200" Orientation="Vertical" Minimum="0" Maximum="1" Value="0.5" />
<Slider Name="sliderPitch" Width="100" Height="200" Orientation="Vertical" Maximum="1" Minimum="-1" Value="0" />
<Slider Name="sliderPan" Width="100" Height="200" Orientation="Vertical" Maximum="1" Minimum="-1" Value="0" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Name="txtVolume" Width="100" TextAlignment="Center" />
<TextBlock Name="txtPitch" Width="100" TextAlignment="Center" />
<TextBlock Name="txtPan" Width="100" TextAlignment="Center" />
</StackPanel>
</StackPanel>
</navigation:Page>
Media/SoundEffectDemo.xaml.cs
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;
using System.Windows.Navigation;
using Microsoft.Xna.Framework.Audio;
using System.Windows.Resources;
namespace Silverlight50.Media
{
/// <summary>
/// Silverlight 5 支持通过 SoundEffect 处理 wav 音效文件
/// 本例演示:如何控制音量,高低音,左右声道平衡
/// </summary>
public partial class SoundEffectDemo : Page
{
/*
* SoundEffect - 音效对象
* SoundEffect.Play(float volume, float pitch, float pan) - 播放音效
* volume - 音量值,0 到 1 之间
* pitch - 高音值, -1 到 1 之间,-1 是纯低音,1 是纯高音
* pan - 左右声道平衡值,-1 到 1 之间,-1 是仅左声道有声,1 是仅右声道有声
* SoundEffect.Duration - 音效的时长
* SoundEffect.Name - 音效对象的名称
*/
/*
* SoundEffectInstance - SoundEffect 的对象实例
* SoundEffect.CreateInstance() - 返回 SoundEffect 对象
* SoundEffectInstance.Volume - 音量值,0 到 1 之间
* SoundEffectInstance.Pitch - 高音值, -1 到 1 之间,-1 是纯低音,1 是纯高音
* SoundEffectInstance.Pan - 左右声道平衡值,-1 到 1 之间,-1 是仅左声道有声,1 是仅右声道有声
* SoundEffectInstance.IsLooped - 是否循环播放
* SoundEffectInstance.Play() - 播放
* SoundEffectInstance.Pause() - 暂停
* SoundEffectInstance.Resume() - 继续播放
* SoundEffectInstance.Stop() - 停止
* SoundEffectInstance.State - 返回音效对象的当前状态 [Microsoft.Xna.Framework.Audio.SoundState 枚举]
* SoundState.Playing - 正在播放状态
* SoundState.Paused - 暂停状态
* SoundState.Stopped - 停止状态
*/
/*
SoundEffectInstance soundEffectInstance = soundEffect.CreateInstance();
soundEffectInstance.Volume = 0.5f;
soundEffectInstance.Pitch = -1f;
soundEffectInstance.Pan = 0f;
soundEffectInstance.IsLooped = true;
soundEffectInstance.Play();
soundEffectInstance.Pause();
soundEffectInstance.Resume();
soundEffectInstance.Stop();
SoundState soundState = soundEffectInstance.State;
*/
private SoundEffect _soundEffect;
private SoundEffectInstance _instance;
public SoundEffectDemo()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(SoundEffectDemo_Loaded);
}
void SoundEffectDemo_Loaded(object sender, RoutedEventArgs e)
{
this.sliderVolume.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderVolume_ValueChanged);
this.sliderPitch.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderPitch_ValueChanged);
this.sliderPan.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderPan_ValueChanged);
// 获取 wav 文件流
StreamResourceInfo musicStream = Application.GetResourceStream(new Uri("Media/rockyou.wav", UriKind.RelativeOrAbsolute));
_soundEffect = SoundEffect.FromStream(musicStream.Stream);
// 设置音效的初始属性
_instance = _soundEffect.CreateInstance();
_instance.IsLooped = true;
_instance.Pitch = 0f;
_instance.Pan = 0f;
_instance.Volume = .5f;
_instance.Play();
}
// 控制音量
private void sliderVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
_instance.Volume = (float)e.NewValue;
txtVolume.Text = e.NewValue.ToString("f2");
}
// 控制高低音
private void sliderPitch_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
_instance.Pitch = (float)e.NewValue; ;
txtPitch.Text = e.NewValue.ToString("f2");
}
// 控制左右声道平衡
private void sliderPan_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
_instance.Pan = (float)e.NewValue; ;
txtPan.Text = e.NewValue.ToString("f2");
}
}
}
3、VectorPrinting(支持矢量打印)
<navigation:Page x:Class="Silverlight50.Other.VectorPrinting"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="VectorPrinting Page">
<Grid x:Name="LayoutRoot">
<TextBlock Text="支持矢量打印了" />
</Grid>
</navigation:Page>
4、ClickCount(统计连击的次数)
Other/ClickCount.xaml
<navigation:Page x:Class="Silverlight50.Other.ClickCount"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="ClickCount Page">
<StackPanel x:Name="LayoutRoot">
<Rectangle Name="rectangle" Width="100" Height="30" Fill="Gray" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" />
<TextBlock Name="txt" />
</StackPanel>
</navigation:Page>
Other/ClickCount.xaml.cs
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;
using System.Windows.Navigation;
namespace Silverlight50.Other
{
public partial class ClickCount : Page
{
public ClickCount()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
/*
* MouseButtonEventArgs.ClickCount - 获取连击的次数
* 注:连击的最大间隔时间是由操作系统的"控制面板"-->"鼠标"-->"双击速度"设置的
*/
if (e.ClickCount == 1) // Single Click
txt.Text = "Left Mouse Click Counter:" + e.ClickCount.ToString();
else if (e.ClickCount == 2) // Double Click
txt.Text = "Left Mouse Click Counter:" + e.ClickCount.ToString();
else // More Click
txt.Text = "Left Mouse Click Counter:" + e.ClickCount.ToString();
}
}
}
分享到:
相关推荐
稳扎稳打 Silverlight 4,在网上收集的资料
风语筑-603466-投资价值分析报告:主业稳扎稳打,技术拓宽边界.pdf
招商秘笈之二稳扎稳打-细节筹备.zip
参考资料-招商秘笈之二稳扎稳打-细节筹备.zip
正确解读新能源汽车产业发展规划,稳扎稳打提升竞争力.pdf
稳扎稳打 纵深发展——在不断创新中引领中国PCB行业走向强盛.pdf
打印机加密SoC 芯片设计-全产业链稳扎稳打,多业务借资本腾飞.pdf
工程内容介绍(由浅入深,稳扎稳打): test1:建立Server和Client。有Client加入,Server广播给所有Client。 test2:在控制台中Server可以给所有Client发送数据,Client可以给Sever和其他Client发送数据。 test3...
公司分析-华西证券-博深股份002282.SZ传统业务稳扎稳打,高铁业务蓄势待发
20210803-华西证券-博深股份-002282-传统业务稳扎稳打,高铁业务蓄势待发.pdf
宏观行业研究方法华泰证券(申银万国)-中报点评-稳扎稳打、步步为营-100419.pdf
20200218-招商-叮咚买菜深度报告,稳扎稳打、垂直聚焦,叮咚买菜的卖菜经
上海证券-皖新传媒(601801)首次覆盖报告:稳扎稳打锐意创新,引领出版转型升级-230524.pdf
稳扎稳打高三化学一轮专讲内蒙专用物质的分类与转化 物质的分散系PPT学习教案.pptx
港股投资周报:稳扎稳打,港股精选组合本周超恒生指数2.05%,今年以来超额收益38.81%.rar
20210729-光大证券-泡泡玛特-9992.HK-跟踪报告:量价齐升市场回暖,稳扎稳打突破边界.pdf
20210819-安信证券-新奥股份-600803-城燃主业稳扎稳打,新兴业务多点开花,兼具确定性与成长性的燃气龙头.rar