我正在使用List來綁定我的應用程序中的列表框。但是我需要添加一個不存在於綁定對象中的外場。我不知道該怎麼做。請任何想法?綁定多個來源到列表框
我的代碼:
ObservableCollection<LatestItemsInfo> lstLatestItem;
lstBoxLatestItems.ItemsSource = lstLatestItem;
CurrencyInfo info = new CurrencyInfo();
info.CurrencySymbol = "$";
我需要這個CURRENCYSYMBOL添加到我的列表框:
我的列表框是這樣的:
<ListBox Name="lstBoxLatestItems">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel Height="160" Width="160" Margin="0">
<Image Height="150" Width="150" ImageFailed="Image_ImageFailed" Stretch="Uniform" Source="{Binding ImagePath}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Height="160" Margin="10" Width="300">
<StackPanel Orientation="Horizontal" Height="40" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" DataContext="{Binding info}">
<TextBlock TextDecorations="Underline" Text="{Binding CurrencySymbol}" TextWrapping="Wrap" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40" VerticalAlignment="Center">
<TextBlock TextDecorations="Underline" Text="{Binding ListPrice}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40" VerticalAlignment="Center">
<TextBlock Text="{Binding Price}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我已經得到了貨幣符號..我只需要在文本塊上顯示它。那麼你可以幫我用代碼... – 2012-02-12 11:00:30
那麼代碼取決於確定正確的貨幣符號所涉及的邏輯。這是一篇關於價值轉換器的博客文章。 http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx – 2012-02-12 22:14:13