Silverlight4の機能強化
Silverlight4のβが出ていたので早速インストール。ホイールマウスに対応したらしいので実験君。
てきとーUI
<UserControl xClass="WheelSample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml" xmlnsd="http://schemas.microsoft.com/expression/blend/2008" xmlnsmc="http://schemas.openxmlformats.org/markup-compatibility/2006" mcIgnorable="d" dDesignHeight="300" dDesignWidth="400"> <Grid xName="LayoutRoot" Background="White" MouseWheel="UserControl_MouseWheel"> <GridRowDefinitions> <RowDefinition Height="Auto"> <RowDefinition> </GridRowDefinitions> <GridColumnDefinitions> <ColumnDefinition> <ColumnDefinition Width="Auto"> </GridColumnDefinitions> <TextBox Name="text1"></TextBox> <Button GridRow="0" GridColumn="1" Name="bnOpen" Click="bnOpen_Click" Content="Open"> <Image Name="image" GridRow="1" GridColumnSpan="2"> <ImageRenderTransform> <RotateTransform xName="rotate"> </ImageRenderTransform> </Image> </Grid> </UserControl>
ダイアログでファイルを選んで表示するコードとホイールで画像を回転するコードを追加。
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.Media.Imaging; namespace WheelSample { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void bnOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == true) { var src = new BitmapImage(); src.SetSource(dlg.File.OpenRead()); image.Source = src; } } private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) { rotate.Angle += e.Delta / 10.0; } } }
Silverlightが強化されるとWPFの立場がだんだん無くなっていくような気が・・・(^^;