Question

I have a ListBox control which is binded to a ObservableCollection.

My XAML code:

<ListBox Margin="12,148,12,90" ItemsSource="{Binding FuelRecords}" Name="ListBox1">
        <ListBox.ItemTemplate>
            <DataTemplate>
               <StackPanel>
                   <TextBlock Text="Fuel quantity: {Binding Quantity}" FontSize="20" />
               </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

I want to display a unit of measure (litre, gallon), after the quantity. The measurement unit is saved using IsolatedStorageSettings in the AppSettings class (VolumeSettingproperty).

End result: Fuel quantity: 23.45 gallon

Was it helpful?

Solution

public class Fuel
{
    public double QuantityGallons { get; set; }

    public double Quantity
    {
        get
        {
            return QuantityGallons * (AppSettings["VolumeSetting"] == Units.Pounds) ? 1.5 : 1.0;
        }
    }

    public string Units
    {
        get
        {
            return (AppSettings["VolumeSetting"] == Units.Pounds) ? "pound" : "gallon";
        }
    }
}

xaml:

<StackPanel Orientation="Horizontal">
    <TextBlock Text="Fuel quantity: " FontSize="20" />
    <TextBlock Text="{Binding Quantity}" FontSize="20" />
    <TextBlock Text="{Binding Units}" FontSize="20" />
</StackPanel>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top