好了··上次講到···childwindows 幹啥的?~》
這次就看看··吧··
如果你之前下載了····PicBtn 這個檔案,···那就應該會有以下的圖片
接著就是他的XAML布局
<controls:ChildWindow x:Class="SilverlightMusicHit.ChildMusicMsg" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Width="400" Height="300" Opacity="0.9" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"> <Grid x:Name="LayoutRoot" Margin="2" LostFocus="LayoutRoot_LostFocus"> <Grid.RowDefinitions> <RowDefinition Height="150"/> <RowDefinition Height="50"/> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Button x:Name="btnStart" Content="START" Width="126" Height="63" HorizontalAlignment="Right" Margin="0,0,125,-28" Grid.Row="2" Opacity="0.5" MouseLeave="btn_MouseLeave" MouseMove="btn_MouseMove" Click="btnStart_Click" /> <Image Height="150" Width="150" HorizontalAlignment="Left" Margin="0,0,0,0" Name="imgMusic" Stretch="Fill" VerticalAlignment="Top" Grid.Row="0" Source="../Image/PicBtn/musicMsg.png"/> <TextBlock Height="140" HorizontalAlignment="Left" Margin="150,10,0,0" Name="txtMusicTitle" VerticalAlignment="Top" Width="230" FontSize="32" Text="txt" TextWrapping="Wrap" /> </Grid></controls:ChildWindow>
- = 怎麼越講越少,····怎麼說呢···其實這些布局···應該還看得懂吧。
進入···ChildMusicMsg.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.Threading;namespace SilverlightMusicHit{ public partial class ChildMusicMsg : ChildWindow { #region 變數 /// <summary> /// 音樂資訊索引 /// </summary> private static int _musicIndex = 0; #endregion public ChildMusicMsg(int musicIndex) { InitializeComponent(); _musicIndex = musicIndex; //讀取音樂資訊 txtMusicTitle.Text = Common._MusicValue[_musicIndex].MusicName; } /// <summary> /// 滑鼠移過按鈕高亮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_MouseMove(object sender, MouseEventArgs e) { ((Button)sender).Opacity = 1; } /// <summary> /// 滑鼠離開按鈕恢複 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_MouseLeave(object sender, MouseEventArgs e) { ((Button)sender).Opacity = 0.5; } private void btnStart_Click(object sender, RoutedEventArgs e) { ((App)(Application.Current)).RedirectTo(new Game(_musicIndex)); this.DialogResult = true; } private void LayoutRoot_LostFocus(object sender, RoutedEventArgs e) { this.DialogResult = true; } }}
噢··還有錯誤,···,嗯,還要建立一個新的表單,··Game , 進入遊戲了··呵呵··· - = 不過下一章才講~
好了··就這樣吧···
name:5+x
參考文章與書籍:
WPF葵花寶典