Esempio n. 1
0
        private void Report(string msg, bool?isFailed = null)
        {
            var color  = new SolidColorBrush(Colors.LightGray);
            var prefix = "";

            if (isFailed == true)
            {
                color  = new SolidColorBrush(Colors.Red);
                prefix = "❌ ";
            }
            else if (isFailed == false)
            {
                color  = new SolidColorBrush(Colors.LightGreen);
                prefix = "✔️ ";
            }

            var ctl = new TextBlock
            {
                Text         = prefix + msg,
                Foreground   = color,
                Margin       = ThicknessHelper.FromLengths(8, 0, 0, 0),
                FontFamily   = new FontFamily("Courier New"),
                FontSize     = 11,
                TextWrapping = TextWrapping.Wrap
            };

            TestsResults.Children.Add(ctl);
            ctl.StartBringIntoView();
        }
        public UIElementCollection_Insert()
        {
            this.InitializeComponent();

            Loaded += (snd, e) =>
            {
                When_Insert_First.Children.Insert(0, new Border
                {
                    Background = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0x00, 0x00)),
                    Margin     = ThicknessHelper.FromUniformLength(0),
                });

                When_Insert_Middle.Children.Insert(3, new Border
                {
                    Background = new SolidColorBrush(Color.FromArgb(0xff, 0x00, 0x80, 0x00)),
                    Margin     = ThicknessHelper.FromLengths(30, 0, 30, 0),
                });

                When_Insert_Last.Children.Add(new Border
                {
                    Background = new SolidColorBrush(Color.FromArgb(0xff, 0xa0, 0x00, 0xc0)),
                    Margin     = ThicknessHelper.FromLengths(50, 0, 50, 0),
                });
            };
        }
        private async void Grid_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
        {
            if (accountSettings.Margin.Right == 0)
            {
                accountSettings.Margin   = ThicknessHelper.FromLengths(0, 0, -346, 0);
                App.Settings["UserName"] = accountSettings.UserName;

                if (accountSettings.UserName.Length > 0 && accountSettings.Password.Length > 0 && !App.isLoggedIn)
                {
                    await LoginReddit();

                    Dispatcher.Invoke(CoreDispatcherPriority.Normal, (x, y) =>
                    {
                        Subreddits = new RedditCollection(App.isLoggedIn);
                        //Subreddits.LoadMoreItemsAsync(25, this.Dispatcher);
                    }, this, null);
                    //App.ShowCollection();
                    //try
                    //{
                    //    var request = (HttpWebRequest)WebRequest.Create("http://www.reddit.com/reddits/mine.json");
                    //    request.CookieContainer = new CookieContainer();

                    //    Cookie c = new Cookie("reddit_session", App.cookie.Replace(",", "%2C"));
                    //    request.CookieContainer.Add(new Uri("http://www.reddit.com"), c);

                    //    RequestState rs = new RequestState();
                    //    rs.Request = request;

                    //    var response = request.BeginGetResponse(new AsyncCallback(RespCallback), rs);
                    //    //LoadCollection(response);
                    //}
                    //catch (Exception)
                    //{

                    //}
                }
                else if (!accountSettings.SavePassword)
                {
                    App.Settings["SavePassword"] = false;
                    Task.Run(() =>
                    {
                        try
                        {
                            var passwords = App.PasswordVault.FindAllByResource("redditMetro");
                            foreach (var pass in passwords)
                            {
                                if (pass.UserName == accountSettings.UserName)
                                {
                                    App.PasswordVault.Remove(pass);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            //user doesn't have a password stored, ignore
                        }
                    });
                }
            }
        }
        public async Task When_TransformToVisual_WithMargin()
        {
            FrameworkElement inner = new Border {
                Width = 100, Height = 100, Background = new SolidColorBrush(Colors.DarkBlue)
            };

            FrameworkElement container = new Border
            {
                Child               = inner,
                Margin              = ThicknessHelper.FromLengths(1, 3, 5, 7),
                Padding             = ThicknessHelper.FromLengths(11, 13, 17, 19),
                BorderThickness     = ThicknessHelper.FromUniformLength(23),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Background          = new SolidColorBrush(Colors.DarkSalmon)
            };
            FrameworkElement outer = new Border
            {
                Child           = container,
                Padding         = ThicknessHelper.FromUniformLength(8),
                BorderThickness = ThicknessHelper.FromUniformLength(2),
                Width           = 300,
                Height          = 300,
                Background      = new SolidColorBrush(Colors.MediumSeaGreen)
            };

            TestServices.WindowHelper.WindowContent = outer;

            await TestServices.WindowHelper.WaitForIdle();

            string GetStr(FrameworkElement e)
            {
                var positionMatrix = ((MatrixTransform)e.TransformToVisual(outer)).Matrix;

                return($"{positionMatrix.OffsetX};{positionMatrix.OffsetY};{e.ActualWidth};{e.ActualHeight}");
            }

            var str = $"{GetStr(container)}|{GetStr(inner)}";

            Assert.AreEqual("111;105;174;178|145;141;100;100", str);
        }