在WP7 ListBox控件中显示应用程序设置

时间:2012-05-29 12:39:12

标签: windows-phone-7 isolatedstorage appsettings listbox-control

我有一个ListBox控件绑定到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>

我想在数量之后显示一个度量单位(升,加仑)。使用IsolatedStorageSettings类(AppSettings属性)中的VolumeSetting保存测量单位。

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

1 个答案:

答案 0 :(得分: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";
        }
    }
}

XAML:

<StackPanel Orientation="Horizontal">
    <TextBlock Text="Fuel quantity: " FontSize="20" />
    <TextBlock Text="{Binding Quantity}" FontSize="20" />
    <TextBlock Text="{Binding Units}" FontSize="20" />
</StackPanel>