C#WPF绑定不起作用

编程入门 行业动态 更新时间:2024-10-26 21:31:53
本文介绍了C#WPF绑定不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 有谁知道为什么我的绑定在此程序中不起作用?

Hi Does anyone know why my binding does not work in this program?

<Window x:Class="WPF_Binding_Example.MainWindow" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:src="clr-namespace:WPF_Binding_Example" xmlns:x="schemas.microsoft/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绑定不起作用

本文发布于:2023-11-10 06:04:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   不起作用   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!