zoukankan      html  css  js  c++  java
  • Silverlight操作网页元素

    Silverlight操作网页元素

    还是通过网页元素的ID得到给元素,然后设置该元素的属性即可

    Html

    1
    <img id="myimg" src="ClientBin/Images/Eagle.jpg" alt="niao"/>

    XAML

    1
    2
    3
    <StackPanel>
            <Slider x:Name="myslider" Maximum="1000" Minimum="0" Value="50" ValueChanged="myslider_ValueChanged"></Slider>
        </StackPanel>

    CS

    1
    2
    3
    4
    5
    private void myslider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
            {
                HtmlElement img = HtmlPage.Document.GetElementById("myimg");
                img.SetAttribute("width",e.NewValue.ToString());
            }

    反之呢?

    我们要改变Silvelight中的元素,那么必须在后台事件中,所以,原理就是把html元素的事件绑定到code-behind即可

    html

    1
    2
    3
    4
    5
    <select id="select">
        <option title="Red" value="Red" selected>Red</option>
        <option title="Blue" value="Blue">Blue</option>
        <option title="Yellow" value="Yellow">Yellow</option>
        </select>

    XAML

    1
    <Ellipse x:Name="myell" Width="200" Height="200" Fill="Red"></Ellipse>

    CS

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    public MainPage()
            {
                InitializeComponent();
                HtmlElement select = HtmlPage.Document.GetElementById("select");
                select.AttachEvent("onchange", new EventHandler<HtmlEventArgs>(Select_onChange));
            }
     
            private void Select_onChange(object sender, HtmlEventArgs e)
            {
                HtmlElement select = HtmlPage.Document.GetElementById("select");
                string Value = select.GetAttribute("value");
                switch (Value)
                {
                    case "Red":
                        myell.Fill = new SolidColorBrush(Colors.Red);
                        break;
                    case "Blue":
                        myell.Fill = new SolidColorBrush(Colors.Blue);
                        break;
                    case "Yellow":
                        myell.Fill = new SolidColorBrush(Colors.Yellow);
                        break;
                    default:
                        break;
                }
            }
  • 相关阅读:
    Linux运维工程师需要掌握什么才能胜任工作呢
    我眼中的Linux系统和红帽RHCE认证
    Linux系统从零到高手的进阶心得
    我在大学毕业后学习Linux系统的心得经验
    装RAC跑脚本报错
    Oracle rac11g 安装报INS41112
    Oracle升级11.2.0.3-11.2.0.4(Windows)
    防存储掉线安装监控软件
    跨平台迁移数据库windows-Linux
    linux crontab -e生成日期格式
  • 原文地址:https://www.cnblogs.com/HelloMyWorld/p/2849440.html
Copyright © 2011-2022 走看看