0

I have a ListBox and some data in there from database. First row is a name (string) and the second row is price which is double. I would like to have word Euros behind the price but in database it should stay as double.

How should I do it?

Listbox with data

Code for my ListBox is:

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

1 Answer 1

1

Use a StringFormat on the unit price TextBlock.

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):

<TextBlock Text="{Binding UnitPrice, StringFormat={}{0} Euros }" />
Sign up to request clarification or add additional context in comments.

1 Comment

more like "StringFormat={}{0:N} Euros", right? he wants the text "Euros" there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.