XAML 中的 .ToString() 怎么说? [英] How do I say .ToString() in XAML?
本文介绍了XAML 中的 .ToString() 怎么说?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码给了我错误(无法将类型对象添加到 Stackpanel).
The following code gives me the error (cannot add type Object to Stackpanel).
如何在 XAML 中说 .ToString()?
How can I say .ToString() in XAML?
<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=FirstName}"/>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListBox x:Name="theCustomers"/>
</Grid>
使用 ADO.NET 实体框架在代码隐藏中绑定:
binding in code-behind with ADO.NET Entity Framework:
MainEntities db = new MainEntities();
var customers = from c in db.CustomersSet
select c;
theCustomers.ItemsSource = customers;
推荐答案
您需要设置属性ContentTemplate
,而不是Content
.
You need to set the property ContentTemplate
, not Content
.
试试:
<Setter Property="ContentTemplate" >
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=FirstName}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding Path=LastName}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
参见 这篇文章
这篇关于XAML 中的 .ToString() 怎么说?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文