C#WPF绑定不起作用 [英] C# WPF binding doesn't work
本文介绍了C#WPF绑定不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
有谁知道为什么我的绑定在此程序中不起作用?
Hi
Does anyone know why my binding does not work in this program?
<Window x:Class="WPF_Binding_Example.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:src="clr-namespace:WPF_Binding_Example"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox x:Name="comboColor" Text="Select Color" ItemsSource="{Binding listColor}" Margin="36,47,243,241">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path= Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</Window>
和clr部分:
and the clr part:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF_Binding_Example
{
public partial class MainWindow : Window
{
List<colorex> colorList = new List<colorex>();
public MainWindow()
{
InitializeComponent();
//////////////////////////////////////////////////////////////////////////
colorList.Add(new ColorEx(Colors.Blue));
colorList.Add(new ColorEx(Colors.Red));
colorList.Add(new ColorEx(Colors.Green));
colorList.Add(new ColorEx(Colors.Yellow));
colorList.Add(new ColorEx(Colors.Pink));
}
}
public class ColorEx
{
Color color = new Color();
public string Name
{
get
{
return this.ToString();
}
}
public ColorEx(Color color)
{
this.color = color;
}
}
}
</colorex></colorex>
推荐答案
我也一直在尝试这样做,网络上有很多链接,但没有实际意义,如果有帮助的话,请取消此链接. .
[ MSDN ^ ]
n plz让我知道您是否克服了数据绑定的问题.
i also have been trying to do that , there are a lot of links on the net but no real thing, chk out this link if its of any help..
[MSDN ^]
n plz let me know if u overcome the problem of databinding..
这篇关于C#WPF绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文