Display app setting in a WP7 ListBox control

175 views Asked by At

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

1

There are 1 answers

1
Ku6opr On BEST ANSWER
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>