2013-01-23 44 views
2

I將ComboBox綁定到實體。 我想組合框來顯示不同格式的每個項目多個值(整數,字符串和日期時間值),就像這樣:綁定Combobox以顯示整數值

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

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

但組合框只顯示了SQL CHAR(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> 

回答

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"