Exemplo n.º 1
0
        public static UIElement[] EnumerateUIElements(DependencyObject root)
        {
            List <UIElement> uiElements = new List <UIElement>();

            UIFunctions.EnumerateUIElements(root, uiElements);

            return(uiElements.ToArray());
        }
Exemplo n.º 2
0
        public async Task Expand(Contractor contractor)
        {
            if (contractor.HasLazyPhoto && (contractor.PhotoRaw == null))
            {
                await ContractorsRepository.Current.Expand(contractor);

                contractor.Photo = await UIFunctions.RawToImage(contractor.PhotoRaw);
            }
        }
Exemplo n.º 3
0
        private async Task InitDataResources()
        {
            UIFunctions.SetFieldsFromResources(typeof(PropertyDialog));

            UIFunctions.SetFieldsFromResources(typeof(MainPage));

            await this.CheckIfDataBaseExist();

            await ContractorsContext.SetCurrentAsync();
        }
Exemplo n.º 4
0
        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);
            }
            ;
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        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;
        }