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;
                }
            }
  • 相关阅读:
    3.2单变量分析 proc univariate
    method of walking——地点定桩法
    韩语陈述句末尾词语法
    数据挖掘简述
    MERGE语句——数据集横向合并
    【转】JavaScript中一个方法同时发送两个ajax请求问题
    ASP.NET MVC中controller和view相互传值的方式
    【转】007.ASP.NET MVC控制器依赖注入
    【转】MVC之 自定义过滤器(ActionFilterAttribute)
    【转】【ASP.NET MVC系列】浅谈ASP.NET 页面之间传值的几种方式
  • 原文地址:https://www.cnblogs.com/HelloMyWorld/p/2849440.html
Copyright © 2011-2022 走看看