Silverlight Project開發

blackhero發表於2007-07-17

Page.xaml
Page.xaml.cs
Silverlight.js
TestPage.html
TestPage.html.js

 ---------------------------------------------------------------------------------------------------------------------------------
Page.xaml:

<Canvas x:Name="parentCanvas"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Loaded="Page_Loaded"
        x:Class="SilverlightProject5.Page;assembly=ClientBin/SilverlightProject5.dll"
        Width="640"
        Height="480"
        Background="White"
        >
       <Canvas Width="100" Height="30" Background="Gray" MouseLeftButtonUp="OnClick">
          <TextBlock>Click me</TextBlock>
       </Canvas>
</Canvas>


Page.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 SilverlightProject5
{
    public partial class Page : Canvas
    {
        public void Page_Loaded(object o, EventArgs e)
        {
            InitializeComponent();
        }

        public void OnClick(object sender, MouseEventArgs e)
        {
            Canvas cc = sender as Canvas;
            SolidColorBrush sb = new SolidColorBrush();
            sb.Color = Colors.Red;
            cc.Background = sb;

            TextBlock tb = cc.Children[0] as TextBlock;
            tb.Text = "Clicked...";
        }
    }
}

---------------------------------------------------------------------------------------------------------------------------

Page.xaml:

<Canvas x:Name="parentCanvas"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Loaded="Page_Loaded"
        x:Class="SilverlightProject5.Page;assembly=ClientBin/SilverlightProject5.dll"
        Width="640"
        Height="480"
        Background="White"
        >
       <Canvas x:Name="Button1" Width="100" Height="30" Background="Gray">  //這裡不同
          <TextBlock>Click me</TextBlock>
       </Canvas>
</Canvas>


Page.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 SilverlightProject5
{
    public partial class Page : Canvas
    {
        public void Page_Loaded(object o, EventArgs e)
        {
            InitializeComponent();
            Button1.MouseLeftButtonUp+=new MouseEventHandler(OnClick);
        }

        public void OnClick(object sender, MouseEventArgs e)
        {
            Canvas cc = sender as Canvas;
            SolidColorBrush sb = new SolidColorBrush();
            sb.Color = Colors.Red;
            cc.Background = sb;

            TextBlock tb = cc.Children[0] as TextBlock;
            tb.Text = "Clicked...";
        }
    }
}

------------------------------------------------------------------------------------------------------------------------

 

 

相關文章