我有一個列表視圖的內容頁面,列表視圖項目從SQLite中挑選。我想定期刷新頁面,以便能夠顯示插入到sql lite中的最新項目。 1.當我第一次添加該記錄的記錄狀態在本地數據庫中「排隊」時,將顯示列表項目,並且該項目的狀態將顯示爲「[員工編號]它排隊等待5分鐘後將同步」。 2. 5分鐘後,所有本地數據庫[Sqlite]將與實際的sql server同步,然後該記錄的狀態將更新爲本地數據庫中的「已完成」,然後狀態我想顯示「[EmployeeNo]它是自動完成「列表視圖中。如何刷新ListPage中的內容頁在xamarin形式定期
-1
A
回答
0
Device.StartTimer (new TimeSpan (0, 0, 10),() => {
// do something every 10 seconds
return true; // runs again, or false to stop
});
2
使用ObservableCollection<T>
作爲你的ItemSource - 它會自動更新每當項目添加或從中
+0
Jason,您好,感謝您的回答。我嘗試使用ObservableCollection
0
公共類EmployeeListPage刪除UI:ContentPage {
ListView listView;
public EmployeeListPage()
{
Title = "Todo";
StartTimer();
var toolbarItem = new ToolbarItem
{
Text = "+",
Icon = Device.OnPlatform(null, "plus.png", "plus.png")
};
toolbarItem.Clicked += async (sender, e) =>
{
await Navigation.PushAsync(new EmployeeItemPage
{
BindingContext = new Employee()
});
};
ToolbarItems.Add(toolbarItem);
listView = new ListView
{
Margin = new Thickness(20),
ItemTemplate = new DataTemplate(() =>
{
var label = new Label
{
VerticalTextAlignment = TextAlignment.Center,
HorizontalOptions = LayoutOptions.StartAndExpand
};
label.SetBinding(Label.TextProperty, "EmployeeName");
var labelText = new Label
{
VerticalTextAlignment = TextAlignment.Center,
HorizontalOptions = LayoutOptions.StartAndExpand
};
label.SetBinding(Label.TextProperty, "EmpStatusDisplayText");
var tick = new Image
{
Source = ImageSource.FromFile("check.png"),
HorizontalOptions = LayoutOptions.End
};
tick.SetBinding(VisualElement.IsVisibleProperty, "IsActive");
var stackLayout = new StackLayout
{
Margin = new Thickness(20, 0, 0, 0),
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
Children = { label, tick }
};
return new ViewCell { View = stackLayout };
})
};
listView.ItemSelected += async (sender, e) =>
{
EmployeeDatabindingDto dto = (e.SelectedItem as EmployeeDatabindingDto);
Employee emp = new Employee {EmployeeID=dto.EmployeeID,EmployeeName=dto.EmployeeName,Salary=dto.Salary,IsActive=dto.IsActive };
Debug.WriteLine("Employee ResumeAt Id = " + emp.EmployeeID);
await Navigation.PushAsync(new EmployeeItemPage
{
BindingContext = emp
});
};
Content = listView;
}
protected override async void OnAppearing()
{
base.OnAppearing();
List<Employee> employees = await App.EmpDatabase.GetItemsAsync();
List<EmployeeDatabindingDto> listBindingDto = await MapEmpWithEmpBindingDto(employees);
listView.ItemsSource = listBindingDto;
}
public async Task<List<EmployeeDatabindingDto>> MapEmpWithEmpBindingDto(List<Employee> employees)
{
List<EmployeeDatabindingDto> bindEmployees = new List<EmployeeDatabindingDto>();
foreach (var employee in employees)
{
string displaysText = "";
string displayDate = "";
displayDate = employee.IsActive == false ? employee.Createddate.ToString() : employee.Modifieddate.ToString();
displaysText = employee.IsActive == false ? string.Format("{0} {1}", "is in queued on", displayDate) : string.Format("{0} {1} ", "is submitted on", displayDate);
bindEmployees.Add(new EmployeeDatabindingDto
{
EmployeeID = employee.EmployeeID
,
EmployeeName = employee.EmployeeName
,
Salary = employee.Salary
,
Createddate = employee.Createddate
,
IsActive = employee.IsActive
,
EmpStatusDisplayText = string.Format("{0} {1}", employee.EmployeeName, displaysText)
});
}
return bindEmployees;
}
private void StartTimer()
{
Device.StartTimer(System.TimeSpan.FromSeconds(10),() =>
{
List<Employee> employees = App.EmpDatabase.GetItemsAsync().Result;
List<EmployeeDatabindingDto> listBindingDto = MapEmpWithEmpBindingDto(employees).Result;
listView.ItemsSource = listBindingDto;
Device.BeginInvokeOnMainThread(UpdateUserDataAsync);
return true;
});
}
private async void UpdateUserDataAsync()
{
await App.EmpDatabase.UpdateEmpStatusAsync();
}
}
相關問題
- 1. 刷新網頁的內容
- 2. 刷新之前的內容頁面Xamarin Forms
- 3. Xamarin形式,ADAL沒有刷新令牌
- 4. 刷新頁面內容無需刷新母版頁中laravel
- 5. 如何刷新QTableView中QCombobox的內容
- 6. Xamarin形式共享項目的新內容頁CS文件不耦合
- 7. 如何在頁面刷新後保留div內容
- 8. 如何在刷新後淡入頁面內容?
- 9. 在Codeigniter/Bootstrap中無頁面刷新加載頁面內容
- 10. 如何刷新一個div的內容
- 11. 如何刷新R gWidget的內容?
- 12. 如何強制刷新DataGridView的內容?
- 13. 如何刷新Div的內容?
- 14. ASP.NET - 在主控頁面更新面板,刷新內容頁面
- 15. Xamarin形式 - 綁定
- 16. Xamarin形式的內容頁面在初始化時滾動到stacklayout
- 17. 如何定期刷新jsp頁面的特定部分
- 18. jquery ajax刷新頁面內容
- 19. 刷新頁面以查看內容
- 20. 刷新頁面內容返回
- 21. Response.End()後刷新頁面內容
- 22. 以Xamarin形式在導航頁面內使用選項卡頁
- 23. 如何在React中渲染新內容之前刷新舊內容?
- 24. 如何保留PHP頁面刷新時的textarea內容?
- 25. 如何刷新網頁視圖的內容
- 26. 如何刷新內容頁面上的項目?
- 27. Xamarin表單:TabbedPage中的內容頁
- 28. 如何刷新表格內容而無需刷新所有頁面
- 29. RoR如何重新刷新刷新內容?
- 30. 如何在一定的時間內停止刷新頁面javascript
謝謝你的回覆,我通過以下網址實現相同http://stackoverflow.com/questions/41574642/refresh-or-update-content-page-every-few-seconds-automatically –
即時通訊新手,我需要把這段代碼放在活動或我的適配器中? – user3373603
活動?這裏是xamarin表單。你可以將它添加到你的頁面構造函數中 –