用Silverlight做了一個導航條.

來源:互聯網
上載者:User
剛接觸Silverlight,還不是很瞭解,就用土辦法做了一個,
效果:滑鼠放到文字串連上,顯示一些懸停效果(用png圖片),點擊時,串連到某個頁面.

1.MenuControl.xaml檔案:<UserControl x:Class="DemoApp.MenuControl"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Canvas Background="#2595EB">
            <Image x:Name="img01" Source="bg.png"  Canvas.Left="10" Canvas.Top="120" Width="80" Height="25" Visibility="Collapsed"></Image>
            <Image x:Name="img02" Source="bg.png"  Canvas.Left="62" Canvas.Top="120" Width="100" Height="25" Visibility="Collapsed"></Image>
            
            <TextBlock x:Name="item01" TextWrapping="Wrap" MouseEnter="item01_MouseEnter" MouseLeave="item01_MouseLeave" MouseLeftButtonUp="item01_MouseLeftButtonUp" Canvas.Left="30" Canvas.Top="120" Text="Index"></TextBlock>
            <TextBlock x:Name="item02" TextWrapping="Wrap" MouseEnter="item02_MouseEnter" MouseLeave="item02_MouseLeave" MouseLeftButtonUp="item02_MouseLeftButtonUp" Canvas.Left="95" Canvas.Top="120" Text="Start"></TextBlock>
                       
            
            <TextBlock x:Name="msg" TextWrapping="Wrap" Canvas.Left="120" Canvas.Top="160"></TextBlock>            
        </Canvas>
    </Grid>
</UserControl>

在這裡,剛開始吧image的定義放到textblock後面了,結果滑鼠放上去,那個圖片一直閃,不穩定.調換後就好了.

2.MenuControl.xaml.cs檔案:using System;
using System.Collections.Generic;
using System.Linq;
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.Browser;

namespace DemoApp
{
    public partial class MenuControl : UserControl
    {
        HtmlWindow html = HtmlPage.Window;

        public MenuControl()
        {
            InitializeComponent();
        }

        private void item01_MouseEnter(object sender, MouseEventArgs e)
        {
            img01.Visibility = Visibility.Visible;
            item01.Cursor = Cursors.Hand;
            msg.Text = "go to index page.";
        }

        private void item01_MouseLeave(object sender, MouseEventArgs e)
        {
            img01.Visibility = Visibility.Collapsed;
            msg.Text = "";
        }

        private void item02_MouseEnter(object sender, MouseEventArgs e)
        {
            img02.Visibility = Visibility.Visible;
            item02.Cursor = Cursors.Hand;
            msg.Text = "go to start page.";
        }

        private void item02_MouseLeave(object sender, MouseEventArgs e)
        {
            img02.Visibility = Visibility.Collapsed;
            msg.Text = "";
        }      

        private void item01_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            html.Navigate(new Uri("/Default.aspx?id=index",UriKind.Relative));
        }

        private void item02_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            html.Navigate(new Uri("Default.aspx?id=start", UriKind.Relative));
        }
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.