【发布时间】:2019-05-08 00:23:30
【问题描述】:
我有一个单一的窗口应用程序,基本上是一个计算器,我可以在其中动态更改各个条目,以根据刚刚输入的新价格/重量等生成新的利润/盈亏平衡答案。每个条目视图都绑定到一个步进值以进行快速的小调整,或者可以编辑条目以进行大的更改。如何保存步进器当前开启的值,以供下次使用应用程序时使用??
<Grid x:Name="PurchasePriceGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width=".6*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Label Text="Purchase Price" TextColor="Black" FontAttributes="Bold" Margin="0,0,25,0" Scale="1.2" TranslationX="15"
Grid.Column="0" HorizontalTextAlignment="End" VerticalTextAlignment="Center" LineBreakMode="NoWrap" />
<customentry:MyEntry x:Name="PurchasePriceEntry" Text="{Binding Source={x:Reference PurchasePriceStepper}, Path=Value, FallbackValue=0}"
TextColor="DarkSlateGray" FontAttributes="Bold" BackgroundColor="Ivory" TranslationX="10"
Grid.Column="1" HorizontalTextAlignment="Center" Keyboard="Numeric" VerticalOptions="End" MaxLength="5"
TextChanged="PurchasePriceEntry_Completed" />
<Stepper x:Name="PurchasePriceStepper" Grid.Column="2" HorizontalOptions="Center" VerticalOptions="Center" Scale=".7" TranslationX="3"
Maximum="5" Minimum=".01" Increment=".01" Value="1.75" />
</Grid>
我不想每次打开应用程序时都必须检查每个条目并更改值以返回到我离开的位置,就像现在一样......我是编程新手,我可以'找不到任何这样的例子供我学习。我猜我需要以某种方式使用 INotifyPropertyChanged 之类的东西,就像这里 Xamarin Forms - update a label value 一样,如果是这样,我该如何使用步进值来做到这一点?或者有没有更好的方法来获得我想要的结果???
【问题讨论】:
-
我刚刚意识到你想要这个用于 xamarin 表单,而不是 winforms。您可以使用 Application.Current.Properties 为以后保存值。这已经在这里回答了stackoverflow.com/questions/37266797/…
-
您想在离开此应用程序之前保存条目中的值吗?并在下次打开应用时显示价值?
-
华华。入口视图从绑定的步进器值中获取其内容,因此步进器值是我需要保存的。
标签: c# xamarin.forms