silverlight乐动魔方 实战八 .

好了··上次讲到···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葵花宝典

原文地址:https://www.cnblogs.com/cheng5x/p/2842986.html