0

我有一个绑定到ObservableCollection.

我的 XAML 代码:

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

我想在数量之后显示一个计量单位(升、加仑)。测量单位保存IsolatedStorageSettingsAppSettings类(VolumeSetting属性)中。

最终结果:燃油量:23.45 加仑

4

1 回答 1

0
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";
        }
    }
}

xml:

<StackPanel Orientation="Horizontal">
    <TextBlock Text="Fuel quantity: " FontSize="20" />
    <TextBlock Text="{Binding Quantity}" FontSize="20" />
    <TextBlock Text="{Binding Units}" FontSize="20" />
</StackPanel>
于 2012-05-29T18:07:03.433 回答