下面实例展示了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="" Width="">
<Grid Background="BlanchedAlmond">
<Canvas Height="" HorizontalAlignment="Left" Margin="12,12,0,0" Name="canvas1" VerticalAlignment="Top" Width="">
<TextBox Canvas.Left="" Canvas.Top="" Height="" Name="textBox1" Width="" />
<TextBox Canvas.Left="" Canvas.Top="" Height="" Name="textBox2" Width="" />
<TextBox Canvas.Left="" Canvas.Top="" Height="" Name="textBox3" Width="" />
<Label Canvas.Left="" Canvas.Top="" Content="OUT:" Height="" Name="label1" />
<Label Canvas.Left="" Canvas.Top="" Content="X:" Height="" Name="label2" />
<Label Canvas.Left="" Canvas.Top="" Content="Y:" Height="" Name="label3" />
<Button Content="+" Height="" Name="button1" Width="" Click="button1_Click" Canvas.Left="" Canvas.Top="" />
<Button Content="-" Height="" Name="button2" Width="" Canvas.Left="" Canvas.Top="" Click="button2_Click" />
<Button Content="*" Height="" Name="button3" Width="" Canvas.Left="" Canvas.Top="" Click="button3_Click" />
<Button Content="/" Height="" Name="button4" Width="" Canvas.Left="" Canvas.Top="" 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

WPF内嵌代码和后台代码简单混合使用的更多相关文章

  1. 原生js实现tab选项卡里内嵌图片滚动特效代码

    <!DOCTYPE HTML><html lang="en-US"><head><meta charset="UTF-8&quo ...

  2. WPF内嵌WCF服务对外提供接口

    要测试本帖子代码请记得管理员权限运行vs. 我写这个帖子的初衷是在我做surface小车的时候有类似的需求,感觉这个功能还挺有意思的,所以就分享给大家,网上有很多关于wcf的文章 我就不一一列举了.公 ...

  3. wpf 分别用 xaml 和后台代码实现 色彩渐变

    xaml 方法: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.micros ...

  4. WPF内嵌网页的两种方式

    在wpf程序中,有时会内嵌网页.内嵌网页有两种方法,一种是使用wpf自带WebBrowser控件来调用IE内核,另一种是使用CefSharp包来调用chrom内核. 一.第一种使用自带WebBrows ...

  5. WPF内嵌CEF控件,与JS交互

    1)安装cefsharp.winform包 打开VS2017,打开nuget,找到cefsharp.winform,安装 问:为什么wpf程序不使用cefsharp.wpf? 答:因为cefwpf 4 ...

  6. Winform/WPF中内嵌BeetleX的HTTP服务

    在新版本的BeetleX.FastHttpApi加入了对netstandard2.0支持,如果程序基于.NetFramework4.6.1来构建WinForm或WPF桌面程序的情况下可以直接把Beet ...

  7. WPF背景透明内嵌WebBrowser不显示问题,即AllowsTransparency = true 和 Webbrowser 等控件显示冲突

    首先感谢两位先导者: 1. 解决 WPF AllowsTransparency = true 和 Webbrowser 等控件显示冲突 原文地址:https://www.cnblogs.com/zhi ...

  8. WPF应用程序内嵌网页

    原文:WPF应用程序内嵌网页 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/shaynerain/article/details/78160984 WPF ...

  9. 『Asp.Net 组件』Asp.Net 服务器组件 内嵌JS:让自己的控件动起来

    代码: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ...

随机推荐

  1. Git 版本控制工具(学习笔记)

    GIT(分布式) 一.Git 初始版本控制工具 1. 安装Git Ubuntu系统下,打开shell界面,输入: sudo apt-get install git-core  之后回车输入密码,即可完 ...

  2. QinQ封装及终结详解

    以下内容摘自正在当当网.京东网.卓越网.互动出版网预售,即将正式发售的<华为交换机学习指南>一书(全书近千页).本书是由华为官方授权,国内第一本,也是唯一一本华为交换机权威学习指南,是华为 ...

  3. Java程序猿学习C++之字符串

    #include <iostream> #include <string.h> using namespace std; int my_len(const char *str) ...

  4. NuGet的使用心得

    前言 上星期发布了NuGet的使用和服务搭建后,同时NuGet在部门里也使用了起来.经过这些天的使用,总结了些小技巧和注意点,希望和大家分享下. 问题提出 使用了NuGet的朋友们估计都知道,在签入代 ...

  5. 比較具体的handle机制

    Android的消息机制,用Android线程间通信的Message机制,Android中Handler的用法--在子线程中更新界面,handler机制 Android的消息机制(一) android ...

  6. Chapter 2 - How to Add a sprite

    Chapter 2 - How to Add a sprite 1. Add image resources 1.1add resources on win32 2. Add a sprite TIP ...

  7. j2ee学习笔记 Filter过滤器

    作用:过滤response和request对象的内容 使用: Filter是J2EE的一个接口,自定义Filter需要实现该接口,并重写所有的方法. Filter提供的方法: init() doFil ...

  8. JS实现图片宽高的等比缩放

    关于图片宽高的等比缩放,其实需求就是让图片自适应父容器的宽高,并且是等比缩放图片,使图片不变形. 例如,需要实现如下的效果: 要实现上面的效果,需要知道图片的宽高,父容器的宽高,然后计算缩放后的宽高. ...

  9. Spring各种传播特性源码实现的概览

    这几天都在分析Spring的源码实现,看到事务管理的部分 我们知道事务的传播特性有下面几种,我标黄的就是最常用的3中传播特性, Sping在发生事务嵌套的时候,会依据内层事务的传播特性,来决定内层是事 ...

  10. 状态CSS

    <span style="background-color: #999999 !important;color:#FFFFFF;font-size: 11px;height: 18px ...