我有一个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加仑
答案 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>