質問

次のコードは、(の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>

を参照してください。この記事

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top