简体   繁体   English

列表框中数据库中的C#数据

[英]C# data from database in listbox

I have a ListBox and some data in there from database. 我有一个ListBox和数据库中的一些数据。 First row is a name ( string ) and the second row is price which is double. 第一行是名称( string ),第二行是价格,是两倍。 I would like to have word Euros behind the price but in database it should stay as double. 我想在价格后加上欧元一词,但在数据库中它应该保持两倍。

How should I do it? 我该怎么办?

带有数据的列表框

Code for my ListBox is: 我的ListBox的代码是:

<ListBox Name="BoozeList" Margin="10,124,0,10" HorizontalAlignment="Left"
             ScrollViewer.VerticalScrollBarVisibility="Visible" Width="233"
             Background="#FF79DCFA" BorderBrush="#FF0040FF">

        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=Name}" />
                    <TextBlock Text="{Binding Path=UnitPrice}"/>

                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.Resources>
            <CollectionViewSource x:Key="BoozesCollection" Source="{Binding Boozes}"/>
            <CollectionViewSource x:Key="JuicesCollection" Source="{Binding Juices}"/>
            <CollectionViewSource x:Key="SnacksCollection" Source="{Binding Snacks}"/>

            <Style TargetType="Border">
                <Setter Property="CornerRadius" Value="15"/>
            </Style>
        </ListBox.Resources>
        <ListBox.ItemsSource>
            <CompositeCollection>
                <CollectionContainer Collection="{Binding Source={StaticResource BoozesCollection}}"/>
                <CollectionContainer Collection="{Binding Source={StaticResource JuicesCollection}}"/>
                <CollectionContainer Collection="{Binding Source={StaticResource SnacksCollection}}"/>
            </CompositeCollection>
        </ListBox.ItemsSource>
    </ListBox>

Use a StringFormat on the unit price TextBlock . 在单价TextBlock上使用StringFormat

If you want to display the euro sign next to the price: 如果要在价格旁边显示欧元符号:

<TextBlock Language="fr" Text="{Binding UnitPrice, StringFormat=C0}" />

Or if you want to display the text "Euros" (thanks to @Milan for pointing this out): 或者,如果您要显示文本“欧元”(感谢@Milan指出):

<TextBlock Text="{Binding UnitPrice, StringFormat={}{0} Euros }" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM