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;
                }
            }
  • 相关阅读:
    [转]ion-slide-box
    [转]Ionic 实现双击返回键退出功能
    [转]highcharts图表入门之:如何让highcharts图表自适应浏览器窗体的大小或者页面大小
    [转]ionic Accordion list three levels
    [转]ionic $state.go passed $stateParams
    [转]ionic tab view hide tab bar
    [转]Ionic + AngularJS angular-translate 国际化本地化解决方案
    [转]Ionic Datepicker
    [转]通过AngularJS directive对bootstrap日期控件的的简单包装
    [转]轻松学习Ionic (四) 修改应用图标及添加启动画面(更新官方命令行工具自动生成)
  • 原文地址:https://www.cnblogs.com/HelloMyWorld/p/2849440.html
Copyright © 2011-2022 走看看