• WPF内嵌代码和后台代码简单混合使用


    下面实例展示了WPF内嵌代码和后台代码混合使用,一个简单基础的实例:

    xaml文件:

    <Window x:Class="WPF内嵌代码和后台代码混合使用.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid Background="BlanchedAlmond">
            <Canvas Height="287" HorizontalAlignment="Left" Margin="12,12,0,0" Name="canvas1" VerticalAlignment="Top" Width="479">
                <TextBox Canvas.Left="147" Canvas.Top="73" Height="23" Name="textBox1" Width="120" />
                <TextBox Canvas.Left="147" Canvas.Top="121" Height="23" Name="textBox2" Width="120" />
                <TextBox Canvas.Left="147" Canvas.Top="173" Height="23" Name="textBox3" Width="120" />
                <Label Canvas.Left="93" Canvas.Top="171" Content="OUT:" Height="28" Name="label1" />
                <Label Canvas.Left="123" Canvas.Top="73" Content="X:" Height="28" Name="label2" />
                <Label Canvas.Left="123" Canvas.Top="119" Content="Y:" Height="28" Name="label3" />
                <Button Content="+" Height="25" Name="button1" Width="75" Click="button1_Click" Canvas.Left="26" Canvas.Top="230" />
                <Button Content="-" Height="25" Name="button2" Width="75" Canvas.Left="139" Canvas.Top="230" Click="button2_Click" />
                <Button Content="*" Height="25" Name="button3" Width="75" Canvas.Left="253" Canvas.Top="230" Click="button3_Click" />
                <Button Content="/" Height="25" Name="button4" Width="75" Canvas.Left="366" Canvas.Top="230" Click="button4_Click" />
                <x:Code>
                    <![CDATA[    
                            void button1_Click(object sender, RoutedEventArgs e)   {    
                                        this.GetValue();    
                                  }    
                
                            int Plus(int x ,int y){
                                return x +y;
                                }
                     void button2_Click(object sender, RoutedEventArgs e)   {    
                                        this.GetValue1();    
                                  }    
                
                            int Minus(int x ,int y){
                                return x -y;
                                }
                    void button3_Click(object sender, RoutedEventArgs e)   {    
                                        this.GetValue2();    
                                  }    
                
                            int Multiply(int x ,int y){
                                return x *y;
                                }
                    void button4_Click(object sender, RoutedEventArgs e)   {    
                                        this.GetValue3();    
                                  }    
                
                            int Divide(int x ,int y){
                                return x /y;
                                }
                      ]]>
                    
                </x:Code>
            </Canvas>
        </Grid>
    </Window>

      后台简单代码:

       public void  GetValue() {
                   this.textBox3.Text = this.Plus(int.Parse(this.textBox1.Text), int.Parse(this.textBox2.Text)).ToString();
                  }
               public void GetValue1()
               {
                   this.textBox3.Text = this.Minus(int.Parse(this.textBox1.Text), int.Parse(this.textBox2.Text)).ToString();
               }
               public void GetValue2()
               {
                   this.textBox3.Text = this.Multiply(int.Parse(this.textBox1.Text), int.Parse(this.textBox2.Text)).ToString();
               }
               public void GetValue3()
               {
                   this.textBox3.Text = this.Divide(int.Parse(this.textBox1.Text), int.Parse(this.textBox2.Text)).ToString();
               }

    效果展示:

    示例下载:http://files.cnblogs.com/BABLOVE/WPF%E5%86%85%E5%B5%8C%E4%BB%A3%E7%A0%81%E5%92%8C%E5%90%8E%E5%8F%B0%E4%BB%A3%E7%A0%81%E6%B7%B7%E5%90%88%E4%BD%BF%E7%94%A8.rar

  • 相关阅读:
    ngix反向代理-之反向
    redux和flux究竟有什么不同, 说点自己的理解
    npm发包记录
    由一个聚焦-focus-事件异常跟踪引起的总结
    git查看分支的几个方法
    test-your-mind-快速测试自己的代码
    contos7 yum安装php7.2与swoole (2)
    php_ thinkphp 时间回滚
    30个php操作redis常用方法代码例子
    redis_php 安装与卸载
  • 原文地址:https://www.cnblogs.com/BABLOVE/p/3231602.html
Copyright © 2020-2023  润新知