C# 绑定组合框以显示整数值

C# 绑定组合框以显示整数值,c#,wpf,binding,combobox,converter,C#,Wpf,Binding,Combobox,Converter,我将组合框绑定到一个实体。 我希望组合框在每个项目上显示不同格式的多个值(整数、字符串和日期时间值),如下所示: Item#1) 100 - Description - 01/01/2013 Item#2) 101 - Description - 01/01/2013 但组合框仅显示SQL字符(C#字符串)值,其他值为空: Item#1) - Description - Item#2) - Description - 我必须使用转换器,是我走错了路,还是有更简单的解

我将组合框绑定到一个实体。 我希望组合框在每个项目上显示不同格式的多个值(整数、字符串和日期时间值),如下所示:

Item#1) 100  - Description - 01/01/2013

Item#2) 101  - Description - 01/01/2013
但组合框仅显示SQL字符(C#字符串)值,其他值为空:

Item#1)     - Description -

Item#2)     - Description - 
我必须使用转换器,是我走错了路,还是有更简单的解决方案

在XAML中

 <UserControl.Resources>
    <CollectionViewSource x:Key="tSCHEDEViewSource" d:DesignSource="{d:DesignInstance my:TSCHEDE, CreateList=True}" />
    <DataTemplate x:Key="SchedaTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=KSCHEDA}" Width="60"></TextBlock>
            <TextBlock Text="{Binding Path=DArticolo}" Width="200"></TextBlock>
            <TextBlock Text=" - " Width="40"></TextBlock>
            <TextBlock Text="{Binding Path=DStorico}" Width="150"></TextBlock>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

<ComboBox ItemTemplate="{StaticResource SchedaTemplate}" Grid.Column="1" Grid.Row="1" Height="23"   HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="23,129,0,0" Name="tSCHEDEComboBox1" SelectedValuePath="KScheda" VerticalAlignment="Top" Width="393">
        <ComboBox.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ComboBox.ItemsPanel>
    </ComboBox>

.edmx模型

<EntityType Name="TSCHEDE">
      <Key>
        <PropertyRef Name="KSCHEDA" />
      </Key>
      <Property Name="KSCHEDA" Type="int" Nullable="false" />
      <Property Name="KLINEA" Type="int" Nullable="false" />
      <Property Name="DSCHEDA" Type="char" MaxLength="30" />
      <Property Name="DSTORICO" Type="datetime" />
      <Property Name="FINSMAN" Type="char" MaxLength="1" />
      <Property Name="DNOTE" Type="char" MaxLength="255" />
      <Property Name="FCANC" Type="char" MaxLength="1" />
      <Property Name="DArticolo" Type="char" MaxLength="60" />
      <Property Name="FFIGLIA" Type="char" MaxLength="1" />
    </EntityType>

我认为您在区分大小写方面存在问题。绑定时,必须完全重写变量的名称

试试这个:

<UserControl.Resources>
    <CollectionViewSource x:Key="tSCHEDEViewSource" d:DesignSource="{d:DesignInstance my:TSCHEDE, CreateList=True}" />
    <DataTemplate x:Key="SchedaTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=KSCHEDA}" Width="60"></TextBlock>
            <TextBlock Text="{Binding Path=DARTICOLO" Width="200"></TextBlock>
            <TextBlock Text=" - " Width="40"></TextBlock>
            <TextBlock Text="{Binding Path=DSTORICO}" Width="150"></TextBlock>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

SelectedValuePath
中,您也有错误的变量,请将其更改为
SelectedValuePath=“KSCHEDA”