WPF DataTemplate控件绑定 [英] WPF DataTemplate controls binding
本文介绍了WPF DataTemplate控件绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对数据模板中的绑定控件有问题,我会把代码给您浪费,任何人都可以告诉我代码中的错误在哪里
XAML代码:
Hi,
I Have a problem with binding controls in Data Template i will chow you the code and any one can tell me where is the error in my code
the XAML code:
<window x:class="BindingTest.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<window.resources>
<datatemplate x:key="t1">
<stackpanel>
<textblock name="txt1DT" height="51" removed="AntiqueWhite&"><textblock>
<textblock name="txt12DT" height="44" removed="Aqua"></textblock>
</textblock></textblock></stackpanel>
</datatemplate>
</window.resources>
<stackpanel>
<telerik:radtransitioncontrol height="105" name="radTransitionControl1" contenttemplate="{StaticResource t1}" width="307" xmlns:telerik="#unknown" />
</stackpanel>
</window>
the code behind:
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 BindingTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new Person();
}
}
}
The Person Class :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace BindingTest
{
public partial class Person : INotifyPropertyChanged
{
private string _name;
private string _lastName;
public string Name
{
get { return _name; }
set
{
_name = value;
this.OnPropertyChanged("Name");
}
}
public string LastName
{
get { return _lastName; }
set
{
_lastName = value;
this.OnPropertyChanged("LastName");
}
}
public Person()
{
_name = "Khaled";
_lastName = "Khaled Maryam";
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(
this, new PropertyChangedEventArgs(propName));
}
}
}
the problem, there is no binding to the data template text box,
can any one help and show where is the my error,or if there are a better way to bind controls in data template??
thanks for helping.
推荐答案
<datatemplate x:key="t1">
<stackpanel>
<textblock name="txt1DT" height="51" removed="AntiqueWhite&"><textblock>
<textblock name="txt12DT" height="44" removed="Aqua"></textblock>
</textblock></textblock></stackpanel>
您需要在此处在文本块中进行绑定.这不见了.
You need binding here in the textblock. This is missing.
这篇关于WPF DataTemplate控件绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文