zoukankan      html  css  js  c++  java
  • xaml控件

    xaml文件

    <DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <Button Name = "button1" Margin = "60">Please Click Me.</Button>
    </DockPanel>
    using System.IO;
    using System.Windows.Markup;
    
    namespace 导入xaml文件控件
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                LoadControl("xaml控件.txt");
            }
    
            public void LoadControl(string xamlFilePath)
            {
                Button but;
                DependencyObject rootElement;
                using (FileStream fs = new FileStream(xamlFilePath, FileMode.Open))
                {
                    rootElement = (DependencyObject)XamlReader.Load(fs);
                }
                this.Content = rootElement;
                but = (Button)LogicalTreeHelper.FindLogicalNode(rootElement, "button1");
                but.Click += btn_click;
            }
            private void btn_click(object sender,RoutedEventArgs e)
            {
                ((Button)sender).Content = "Yes";
            }
        }
    }

  • 相关阅读:
    课后listview作业
    安卓sql
    activity带数据跳转
    安卓第四周作业
    15周作业
    十三周作业-集合
    十三周上机练习
    12周作业
    linux
    Questions.
  • 原文地址:https://www.cnblogs.com/riversouth/p/10346821.html
Copyright © 2011-2022 走看看