protected override void SetBindingContext() { typePicker = ControlFactory.CreatePicker(); typePicker.SelectedIndexChanged += TypePicker_SelectedIndexChanged; typePicker.SelectedItemChanged += Picker_SelectedItemChanged; projectPicker = ControlFactory.CreatePicker(); projectPicker.HorizontalOptions = LayoutOptions.FillAndExpand; projectPicker.SelectedItemChanged += Picker_SelectedItemChanged; // Create a filter for showing projects only if the time entry can be edited. if (this.ViewModel.CanEdit()) { filterIcon = ControlFactory.CreateIcon(LabelHandler.FILTER_SYMBOL, ControlFactory.Small_Label_Icon); } projectTaskPicker = ControlFactory.CreatePicker(); projectTaskPicker.HorizontalOptions = LayoutOptions.FillAndExpand; projectTaskPicker.SelectedItemChanged += Picker_SelectedItemChanged; transactionDatePicker = ControlFactory.CreateDatePicker("Time.msdyn_date_utc", DateTime.MaxValue, "D"); // Use a one-way binding from view model to view because of the custom formatting that we have. We want the user to be able to type anything in the text box // but on losing focus from the field, we validate and store the duration in the view model. durationEntry = ControlFactory.CreateEntry("Time.msdyn_duration", BindingMode.OneWay, Keyboard.Default, null, "", new DurationTo24HourStringConverter()); durationEntry.Unfocused += DurationEntry_Unfocused; internalDescriptionEditor = ControlFactory.CreateEditor("Time.msdyn_description"); internalDescriptionEditor.TextChanged += this.createEditorTextChangedHandler(msdyn_timeentry.DescriptionLength); externalDescriptionEditor = ControlFactory.CreateEditor("Time.msdyn_externalDescription"); externalDescriptionEditor.TextChanged += this.createEditorTextChangedHandler(msdyn_timeentry.DescriptionLength); this.BindingContext = ViewModel; }
protected override void SetBindingContext() { projectPicker = ControlFactory.CreatePicker(null, ViewModel.OnProjectSelected); categoryPicker = ControlFactory.CreatePicker(null, ViewModel.OnCategorySelected); currencyPicker = ControlFactory.CreatePicker(null, ViewModel.OnCurrencySelected); transactionDatePicker = ControlFactory.CreateDatePicker("Expense.msdyn_TransactionDate_utc", DateTime.Today, "D"); descriptionEditor = ControlFactory.CreateEditor("Expense.msdyn_name"); descriptionEditor.TextChanged += this.createEditorTextChangedHandler(msdyn_timeentry.DescriptionLength); amountEntry = ControlFactory.CreateEntry("Expense.TransactionAmount", BindingMode.TwoWay, Keyboard.Numeric, "{0:N2}", String.Format("{0:N2}", 0)); amountEntry.Focused += (s, e) => { if (amountEntry.Text.Equals("0.00") || amountEntry.Text.Equals("0")) { amountEntry.Text = String.Empty; } }; salesTaxEntry = ControlFactory.CreateEntry("Expense.SalesTaxAmount", BindingMode.TwoWay, Keyboard.Numeric, "{0:N2}", String.Format("{0:N2}", 0)); salesTaxEntry.Focused += (s, e) => { if (salesTaxEntry.Text.Equals("0.00") || salesTaxEntry.Text.Equals("0")) { salesTaxEntry.Text = String.Empty; } }; this.BindingContext = ViewModel; }
/// <summary> /// Items property is not currently bindable so adding code to manually set items. /// When an item is selected will call the delegate method /// </summary> /// <param name="picker"></param> /// <param name="items">List of items to display in the picker, the key is used as display label</param> /// <returns></returns> public static PickerEx SetItems(PickerEx picker, ICollection <string> items) { picker.Items.Clear(); if (items != null) { foreach (string key in items) { picker.Items.Add(key); } } return(picker); }
private void TypePicker_SelectedIndexChanged(object sender, EventArgs e) { PickerEx picker = (PickerEx)sender; if (picker.SelectedItem != null && projectInfoLayout != null) { msdyn_timeentrytype type = ((msdyn_timeentrytype[])picker.ItemsSource)[picker.SelectedIndex]; projectInfoLayout.IsVisible = (type == msdyn_timeentrytype.Work); if (type != msdyn_timeentrytype.Work) { this.ViewModel.Time.msdyn_project = null; } } }
public ExpenseTabbedPage(ExpenseCollectionViewModel viewModel) : base() { this.viewModel = viewModel; // Main layout StackLayout mainLayout = new StackLayout(); mainLayout.Spacing = 0; mainLayout.VerticalOptions = LayoutOptions.FillAndExpand; mainLayout.HorizontalOptions = LayoutOptions.FillAndExpand; // Title only on windows phone. There is a title added for the other platforms. Device.OnPlatform(WinPhone: () => { Label header = new Label(); header.SetBinding(Label.TextProperty, "Title"); header.Style = (Style)Application.Current.Resources["Label_PageHeader"]; mainLayout.Children.Add(header); }); // Status filter statusSwitcher = ControlFactory.CreatePicker( null, viewModel.OnExpenseStatusSelected, Enum.GetNames(typeof(ExpenseCollectionViewModel.ExpenseStatus)), (int)ExpenseCollectionViewModel.ExpenseStatus.Draft); // List view this.initializeListView(); // No items found label noItemsLabel = new Label { Text = AppResources.NoEntries, HorizontalOptions = LayoutOptions.Center, IsVisible = false, HeightRequest = 50 }; mainLayout.Children.Add(statusSwitcher); mainLayout.Children.Add(noItemsLabel); mainLayout.Children.Add(listView); this.Content = mainLayout; // We only update the visibility bindings once the first load completes this.viewModel.LoadExpensesCompleted += this.ViewModel_LoadExpensesCompleted; }
/// <summary> /// Create a picker with the optional title and selectedIndexChange event method. /// </summary> /// <param name="titleLabel">Title on top of the list items.</param> /// <param name="selectedIndexChangeDelegate">Method to call when the event SelectedItemChanged is triggered on the picker control.</param> /// <param name="itemsSource">Items to show in the picker.</param> /// <param name="startIndex">Index of the initially selected item.</param> /// <returns>A new instance of PickerEx control.</returns> public static PickerEx CreatePicker(string titleLabel, SelectItemAction selectedIndexChangeDelegate, IEnumerable itemsSource, int startIndex) { string title = titleLabel == null ? null : titleLabel; PickerEx picker = new PickerEx(); if (!String.IsNullOrEmpty(title)) { picker.Title = title; } picker.ItemsSource = itemsSource; // Set the initial index before adding a handler. picker.SelectedIndex = startIndex; if (selectedIndexChangeDelegate != null) { int previousIndex = picker.SelectedIndex; picker.SelectedIndexChanged += async(sender, args) => { if (picker.SelectedIndex > -1 && picker.SelectedIndex != previousIndex) { string key = picker.Items[picker.SelectedIndex]; if (await selectedIndexChangeDelegate(key, picker.SelectedIndex)) { previousIndex = picker.SelectedIndex; } else { // Set back to previous index picker.SelectedIndex = previousIndex; } } }; } return(picker); }