2

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

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

Item#2) 101  - Description - 01/01/2013

但 ComboBox 仅显示 SQL char (C# string) 值,其他为空:

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>
4

1 回答 1

2

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

试试这个:

<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".

于 2013-01-23T16:12:24.237 回答