您绑定的对象有问题。我从头创建了一个从DependencyObject继承的Person类的应用程序。我没有设置第一个和最后一个名称属性,我没有看到DependencyProperty.UnsetValue,而是一个只有逗号的空白TextBox。
(一般情况下,你不应该用你的业务对象的依赖属性无妨。坚持INotifyPropertyChanged的并保存自己吨头痛。)
邮政代码到你绑定的对象,也许我可以当场问题。
public class Person : DependencyObject
{
public static readonly DependencyProperty FirstNameProperty = DependencyProperty.Register("FirstName", typeof(string), typeof(Person), new FrameworkPropertyMetadata());
public string FirstName {
get { return (string)GetValue(FirstNameProperty); }
set { SetValue(FirstNameProperty, value); }
}
public static readonly DependencyProperty LastNameProperty = DependencyProperty.Register("LastName", typeof(string), typeof(Person), new FrameworkPropertyMetadata());
public string LastName {
get { return (string)GetValue(LastNameProperty); }
set { SetValue(LastNameProperty, value); }
}
}
-
<TextBox IsReadOnly="True">
<TextBox.Text>
<MultiBinding StringFormat="{}{1}, {0}">
<Binding Path="FirstName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBox.Text>
</TextBox>
-
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}
private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
var p = new Person();
//p.FirstName = "Josh";
//p.LastName = "Einstein";
DataContext = p;
}
}
不清楚。试着看看VS中的输出窗口,在那里你可以看到所有的绑定错误。 DataContext中绑定了什么=“{Binding}”? – SeeSharp 2011-01-25 04:47:34