WPF Combobox数据绑定 Binding
combobox数据绑定List链表集合区分显示值与选择的值
整体效果:

根据combobox选择情况分别打印选取值与显示值
代码:
Windows窗体:
<Window x:Class="ComboxBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ComBox绑定" Height="192.857" Width="385" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
<Grid>
<ComboBox Name="comBox1" HorizontalAlignment="Left" Margin="74,10,0,0" Width="209" Height="22" VerticalAlignment="Top"/>
<TextBlock Name="txtSelectedValue" Width="200" Text="{Binding ElementName=comBox1, Path=SelectedValue}" HorizontalAlignment="Left" Margin="115,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FFE7FBFA"/>
<TextBlock Name="txtSelectedText" Width="200" Text="{Binding ElementName=comBox1, Path=Text}" HorizontalAlignment="Left" Margin="114,88,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Background="#FFE7FBFA"/>
<Label Content="selectedValue" HorizontalAlignment="Left" Margin="2,58,0,0" VerticalAlignment="Top"/>
<Label Content="selectedText" HorizontalAlignment="Left" Margin="10,86,0,0" VerticalAlignment="Top"/> </Grid>
</Window>
Xaml
using System.Collections.Generic;
using System.Windows; namespace ComboxBinding
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<ComboxBind> lstCmbBind = new List<ComboxBind>();//用于绑定数据源 //初始化数据源
ComboxBind cbb = new ComboxBind("显示值1", "选取值1");
lstCmbBind.Add(cbb);
cbb = new ComboxBind("显示值2", "选取值2");
lstCmbBind.Add(cbb);
cbb = new ComboxBind("显示值3", "选取值3");
lstCmbBind.Add(cbb); this.comBox1.ItemsSource = lstCmbBind;
comBox1.DisplayMemberPath = "CmbText";//类ComboxBind中的属性
comBox1.SelectedValuePath = "CmbValue";//类ComboxBind中的属性
}
}
}
用于绑定combobox的类
namespace ComboxBinding
{
/// <summary>
/// 用于Combox数据绑定
/// </summary>
class ComboxBind
{
//构造函数
public ComboxBind(string _cmbText, string _cmbValue)
{
this.cmbText = _cmbText;
this.cmbValue = _cmbValue;
} //用于显示值
private string cmbText;
public string CmbText
{
get { return cmbText; }
set { cmbText = value; }
} //用于实际选取的值
private string cmbValue;
public string CmbValue
{
get { return cmbValue; }
set { cmbValue = value; }
}
}
}
C#
WPF Combobox数据绑定 Binding的更多相关文章
- WPF combobox数据绑定和数据获取
本文章仅为个人学习,如有错误之处请指正. 搭建WPF界面的时候,想用combobox构建一个下拉菜单,搜索的时候看到大多数都是大段代码,逻辑顺序不是很详细,摸索了大概,记录一下方便来者. 拖入comb ...
- WPF数据绑定Binding(二)
WPF数据绑定Binding(二) 1.UI控件直接的数据绑定 UI对象间的绑定,也是最基本的形式,通常是将源对象Source的某个属性值绑定 (拷贝) 到目标对象Destination的某个属性上. ...
- WPF ComboBox Binding
public ConnectionViewModel { private readonly CollectionView _phonebookEntries; private string _phon ...
- wpf Content数据绑定StringFormat起作用的原理和解决
原文:wpf Content数据绑定StringFormat起作用的原理和解决 <Window x:Class="WpfOne.Bind.Bind6" xmlns=" ...
- WPF ComboBox 默认选中无效
在WPF开发当中,我发现ComboBox的默认选中逻辑失效了,仔细查找后发现后台逻辑并没有出现问题. 测试后发现在XAML中,ComBoBox控件的SelectedValue属性需要写在ItemSou ...
- WPF:数据绑定总结(1) https://segmentfault.com/a/1190000012981745
WPF:数据绑定总结(1) visual-studio c# 1.3k 次阅读 · 读完需要 16 分钟 0 一.概念:什么是数据绑定? WPF中的数据绑定:是在应用程序 UI 与业务逻辑之间建立 ...
- C# WinForm 中ComboBox数据绑定的问题 (转)
来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...
- 【转】WPF中的Binding技巧(二)
WPF中的Binding技巧(二) 接上篇, 我们来看一看Elementname,Source,RelativeSource 三种绑定的方式 1.ElementName顾名思义就是根据Ui元素 ...
- combobox数据绑定
jquery easyui datagrid 可编辑行 combobox数据绑定问题 将带有参数的url地址赋值给变量,然后将变量赋值给url <script type="text/j ...
随机推荐
- docker+ubuntu14.04+cuda7.0
参考链接: http://tleyden.github.io/blog/2014/10/25/docker-on-aws-gpu-ubuntu-14-dot-04-slash-cuda-6-dot-5 ...
- css 颜色表示法
css颜色值主要有三种表示方法: (1)颜色名表示,如:red红色,gold金色 (2)rgb表示,如:rgb(255,0,0)表示红色 (3)16进制数值表示,如:#ff0000表示红色,这种可以简 ...
- 字典树-THE XOR largest pair
题目:给你n个数字A1,A2....An ,问从中选出两个数字异或运算得到的最大结果是多少 0<=Ai<231 用字典树,记录每个数字的31位2进制01串(int 为4个字节,每个字节8个 ...
- ECMA Script 6_RegExp 正则表达式
在 ES5 中 RegExp 构造函数的参数有两种情况 RegExp(字符串, 正则表达式的修饰符) RegExp(正则表达式); var regex = new RegExp('xyz', 'i') ...
- [LeetCode] Largest Triangle Area 最大的三角区域
You have a list of points in the plane. Return the area of the largest triangle that can be formed b ...
- jsp模板继承
jsp通过自定义标签实现类似模板继承的效果 关于标签的定义.注册.使用在上面文章均以一个自定义时间的标签体现,如有不清楚自定义标签流程的话请参考这篇文章 http://www.cnblogs.com/ ...
- node 学习(二)
写基础太麻烦了 我花了个基础知识的脑图
- python联系-迭代器
from collections import Iterable from collections import Iterator import time class Classmate(object ...
- vins-mono中的imu参数设置
na:加速度计的测量噪声 nw:陀螺仪的测量噪声 nba: randow walk noise随机游走噪声 nbw:randow walk noise随机游走噪声 ba:加速度计的偏差 bw:陀螺仪的 ...
- WebBrowser 打印
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RTMInterViewInfo ...