【发布时间】:2018-03-01 16:53:12
【问题描述】:
我已经阅读了有关消息传递、触发器、行为等的信息……对于我想要完成的工作来说,这一切似乎都有些矫枉过正。
我在 xaml 中有一个重复的数据输入屏幕,它有 1 个选择器、2 个条目和 1 个按钮。选择器一旦选择了一个值,就会保留该选择。第一个条目与选择器相同。第二个条目是始终获得新值的条目。
我想在单击按钮时收集填充的值,然后清除其数据的最后一个输入字段并将焦点重新放在该条目上,以便用户可以输入新值并点击保存。重复重复重复等。
我了解 MVVM 模型和理论 - 但我只想将重点放在 xaml 视图中的输入字段上,我完全被难住了。
编辑以添加代码示例
view.xaml:
<StackLayout Spacing="5"
Padding="10,10,10,0">
<Picker x:Name="Direction"
Title="Select Direction"
ItemsSource="{Binding Directions}"
ItemDisplayBinding="{Binding Name}"
SelectedItem="{Binding SelectedDirection}"/>
<Label Text="Order"/>
<Entry Text="{Binding Order}"
x:Name="Order" />
<Label Text="Rack"/>
<Entry Text="{Binding Rack}"
x:Name="Rack" />
<Button Text="Save"
Style="{StaticResource Button_Primary}"
Command="{Binding SaveCommand}"
CommandParameter="x:Reference Rack" />
<Label Text="{Binding Summary}"/>
</StackLayout>
viewmodel.cs
public ICommand SaveCommand => new DelegateCommand<View>(PerformSave);
private async void PerformSave(View view)
{
var scan = new Scan()
{
ScanType = "Rack",
Direction = SelectedDirection.Name,
AreaId = 0,
InsertDateTime = DateTime.Now,
ReasonId = 0,
ScanItem = Rack,
OrderNumber = Order,
ScanQty = SelectedDirection.Value,
IsUploaded = false
};
var retVal = _scanService.Insert(scan);
if (!retVal)
{
await _pageDialogService.DisplayAlertAsync("Error", "Something went wrong.", "OK");
}
else
{
view?.Focus();
Rack = string.Empty;
Summary = "last scan was great";
}
}
此部分出现错误:
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(RackPage));
Direction = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Picker>(this, "Direction");
Order = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Entry>(this, "Order");
Rack = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Entry>(this, "Rack");
}
【问题讨论】:
-
页面初始化部分出错
标签: xamarin xamarin.forms prism