どのように私は、XAMLで.ToString()は言うのですか?
質問
次のコードは、(のStackPanelにObject型を追加することはできません)私にエラーを与えます。
私は、XAMLで.ToString()を言うことができる方法は?
<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エンティティフレームワークで結合
MainEntities db = new MainEntities();
var customers = from c in db.CustomersSet
select c;
theCustomers.ItemsSource = customers;
解決
あなたはContentTemplate
ない、プロパティ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>
所属していません StackOverflow