public static UIElement[] EnumerateUIElements(DependencyObject root) { List <UIElement> uiElements = new List <UIElement>(); UIFunctions.EnumerateUIElements(root, uiElements); return(uiElements.ToArray()); }
public async Task Expand(Contractor contractor) { if (contractor.HasLazyPhoto && (contractor.PhotoRaw == null)) { await ContractorsRepository.Current.Expand(contractor); contractor.Photo = await UIFunctions.RawToImage(contractor.PhotoRaw); } }
private async Task InitDataResources() { UIFunctions.SetFieldsFromResources(typeof(PropertyDialog)); UIFunctions.SetFieldsFromResources(typeof(MainPage)); await this.CheckIfDataBaseExist(); await ContractorsContext.SetCurrentAsync(); }
private static void EnumerateUIElements(DependencyObject root, List <UIElement> uiElements) { var uiRoot = root as UIElement; if (uiRoot != null) { uiElements.Add(uiRoot); } int count = VisualTreeHelper.GetChildrenCount(root); for (int i = 0; i < count; i++) { DependencyObject current = VisualTreeHelper.GetChild(root, i); UIFunctions.EnumerateUIElements(current, uiElements); } ; }
private void BuildTextBoxesMap() { this.mTextBoxesMap = new Dictionary <string, TextBox>(); this.mResetValidationMap = new Dictionary <string, PropertyInfo>(); var notificationsPropertyMap = DataTypeFactory.Current.GetNotifications(typeof(Contractor)); var lengthLimits = DataTypeFactory.Current.MaxLength(typeof(Contractor)); var elements = UIFunctions.EnumerateUIElements(this.ucRoot); var textBoxesBind = UIFunctions.GetTextBoxesWithBindedText(elements); foreach (var textBoxBind in textBoxesBind) { this.mTextBoxesMap.Add(textBoxBind.Item2, textBoxBind.Item1); int maxLength; if (lengthLimits.TryGetValue(textBoxBind.Item2, out maxLength)) { textBoxBind.Item1.MaxLength = maxLength; } PropertyInfo info; if (notificationsPropertyMap.TryGetValue(textBoxBind.Item2, out info)) { if (string.IsNullOrEmpty(textBoxBind.Item1.Name)) { throw new ArgumentNullException(); } this.mResetValidationMap.Add(textBoxBind.Item1.Name, info); textBoxBind.Item1.TextChanged += this.ResetTextBox_InvalidState; } } }
private async void ChoosePhoto() { var fileOpenPicker = new FileOpenPicker(); fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.FileTypeFilter.Add(".jpeg"); fileOpenPicker.FileTypeFilter.Add(".bmp"); fileOpenPicker.FileTypeFilter.Add(".tiff"); fileOpenPicker.FileTypeFilter.Add(".ico"); var storageFile = await fileOpenPicker.PickSingleFileAsync(); if (storageFile == null) { return; } var pointer = Window.Current.CoreWindow.PointerCursor; Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 1); using (IRandomAccessStream stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read)) { byte[] fileBytes = new byte[stream.Size]; using (DataReader reader = new DataReader(stream)) { await reader.LoadAsync((uint)stream.Size); reader.ReadBytes(fileBytes); try { this.iContractor.Photo = await UIFunctions.RawToImage(fileBytes); } catch (Exception e) { if (e.HResult == -2003292336) { Window.Current.CoreWindow.PointerCursor = pointer; var dialog = new MessageDialog("То что вы пытаетесь присвоить - технически не совсем изображение"); dialog.Commands.Add(new UICommand("Закрыть")); dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 0; await dialog.ShowAsync(); return; } else { throw; } } this.iContractor.PhotoRaw = fileBytes; this.ImageHint = ZoomImageHint; } } Window.Current.CoreWindow.PointerCursor = pointer; }