在XAML中如何表示.ToString()?

在XAML中如何表示.ToString()?,xaml,tostring,Xaml,Tostring,以下代码给出了错误(无法将类型对象添加到Stackpanel) 如何在XAML中说出.ToString() 您需要设置属性ContentTemplate,而不是Content 尝试: 请参见您需要设置属性ContentTemplate,而不是Content 尝试: 请参见非常好,这很有效,您知道在这种情况下如何使用StringFormat吗?很好,这很有效,你知道我如何在这种情况下使用StringFormat吗? <Window.Resources> <Styl

以下代码给出了错误(无法将类型对象添加到Stackpanel)

如何在XAML中说出.ToString()


您需要设置属性
ContentTemplate
,而不是
Content

尝试:



请参见您需要设置属性
ContentTemplate
,而不是
Content

尝试:



请参见

非常好,这很有效,您知道在这种情况下如何使用StringFormat吗?很好,这很有效,你知道我如何在这种情况下使用StringFormat吗?
<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>
MainEntities db = new MainEntities();
var customers = from c in db.CustomersSet
                select c;
theCustomers.ItemsSource = customers;
<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>