0

我有一個綁定到ObservableCollection的ListBox控件。在WP7 ListBox控件中顯示應用程序設置

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

我想顯示的計量單位(升,加侖),經量。在AppSettings類(VolumeSetting屬性)中使用IsolatedStorageSettings保存測量單位。

最終結果: 燃料量:23.45加侖

回答

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

的_VolumeSetting_是一個常數。我從'AppSettings'類閱讀它。 – milo2011

+0

看我的更新... – Ku6opr

+0

謝謝你,Ku6opr! – milo2011

相關問題