public static TChild GetLastVisualChild <TChild>(this DependencyObject obj, Predicate <TChild> predicate = null) where TChild : DependencyObject { if (obj == null) { return(null); } var count = VisualTreeHelper.GetChildrenCount(obj); for (int i = count - 1; i >= 0; i--) { var c = VisualTreeHelper.GetChild(obj, i); var r = c as TChild; if (r != null && (predicate == null || predicate(r))) { return(r); } r = GetLastVisualChild(c, predicate); if (r != null) { return(r); } } return(null); }
/*private void IDSearch_Is_Focused(object sender, System.Windows.RoutedEventArgs e) * { * SolidColorBrush brush = new SolidColorBrush(Color.FromRgb(224, 255, 255)); * IDSearch.Text = ""; * IDSearch.Foreground = brush; * } * * private void IDSearch_Lost_Focus(object sender, System.Windows.RoutedEventArgs e) * { * IDSearch.Text = "Find person with ID"; * IDSearch.Foreground = Brushes.Silver; * } * * private void ID_Entered(object sender, KeyEventArgs e) * { * if (e.Key == Key.Enter) * { * idsob = Convert.ToInt32(IDSearch.Text); * var StartDialogThread = new Thread(() => StartDialog(idsob, MainWindow.api, Utils.AsimDecryptor.GetPrivKey(), Utils.SimCrypto.GetSimKeyforMes())); * StartDialogThread.Start(); * } * }*/ private void ElementSelected(object sender, MouseButtonEventArgs e) { ListBoxItem listitem = (ListBoxItem)FullFriendList.SelectedItem; object item = listitem.Content; Grid frgr = VTH.GetChild(item as DependencyObject, 0) as Grid; TextBlock text = VTH.GetChild(frgr as DependencyObject, 0) as TextBlock; object id = listitem.Tag; ActiveUserId = Convert.ToInt64(id.ToString()); using (SQLiteConnection CrFile_Connection = new SQLiteConnection("Data Source=Current_Dialogs.sqlite;")) { CrFile_Connection.Open(); string sql = string.Format("select * from active_users where id=={0}", Convert.ToInt32(id.ToString())); SQLiteCommand command = new SQLiteCommand(sql, CrFile_Connection); SQLiteDataReader res = command.ExecuteReader(); if (res.HasRows == true) { if (res.Read()) { int subid = (int)res["id"]; string pubkey = (string)res["pubkey"]; string simkey = (string)res["simkey"]; ActivePubKey = pubkey; ActiveSimKey = simkey; } } //string result = command.ExecuteScalar().ToString(); CrFile_Connection.Close(); } //var StartDialogThread = new Thread(() => StartDialog(idsob, MainWindow.api, Utils.AsimDecryptor.GetPrivKey(), Utils.SimCrypto.GetSimKeyforMes())); //StartDialogThread.Start(); }
public static DependencyObject GetFirstVisualChild(this DependencyObject obj) { return(VisualTreeHelper.GetChild(obj, 0)); }
public static DependencyObject GetParent(this DependencyObject obj) { return(obj is System.Windows.Media.Visual ? VisualTreeHelper.GetParent(obj) : LogicalTreeHelper.GetParent(obj)); }
public void CreateFriendsList() { var friend_list = MainWindow.api.Friends.Get(new FriendsGetParams { Order = FriendsOrder.Hints, Fields = ProfileFields.FirstName | ProfileFields.Photo50, Count = 6000, NameCase = NameCase.Nom, }); /*_ = Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(delegate * { * FullFriendList.Items.Add(MainWindow.api.Account.GetProfileInfo().FirstName + ' ' + MainWindow.api.Account.GetProfileInfo().LastName + " ID:" + MainWindow.api.UserId); * }));*/ int friendnum = 0; foreach (var friend in friend_list) { using (WebClient webClient = new WebClient()) { try { webClient.DownloadFile(friend.Photo50.AbsoluteUri, (Path.Combine(Environment.CurrentDirectory, "Friendava" + friendnum.ToString() + ".jpg"))); } catch { } } Dispatcher.BeginInvoke(new ThreadStart(delegate { ListBoxItem itemfriend = new ListBoxItem(); itemfriend.Name = "frienditem" + friendnum.ToString(); StackPanel itemstack = new StackPanel(); itemstack.Name = "friendstack" + friendnum.ToString(); Grid itemgrid = new Grid(); for (int i = 0; i < 8; i++) { itemgrid.ColumnDefinitions.Add(new ColumnDefinition()); } for (int i = 0; i < 3; i++) { itemgrid.RowDefinitions.Add(new RowDefinition()); } itemgrid.Name = "friendgrid" + friendnum.ToString(); itemstack.Children.Add(itemgrid); TextBlock friendinfo = new TextBlock(); friendinfo.Text = " " + friend.FirstName + " " + friend.LastName; friendinfo.FontSize = 15; Grid.SetColumn(friendinfo, 5); Grid.SetColumnSpan(friendinfo, 4); Grid.SetRow(friendinfo, 1); Grid.SetRowSpan(friendinfo, 2); itemgrid.Children.Add(friendinfo); itemfriend.Content = itemstack; itemfriend.Tag = friend.Id; FullFriendList.Items.Add(itemfriend); FullFriendList.UpdateLayout(); })); friendnum++; } _ = Dispatcher.BeginInvoke(new ThreadStart(delegate { int num = 0; System.Collections.IEnumerable nodes = LTH.GetChildren(FullFriendList); foreach (var node in nodes) { //MessageBox.Show(node.GetType().ToString()); if (node is string) { continue; } Visual listitem = (Visual)node; System.Collections.IEnumerable items = LTH.GetChildren(listitem); foreach (var item in items) { if (item is StackPanel) { Grid frgr = VTH.GetChild(item as DependencyObject, 0) as Grid; ImageBrush friendava = new ImageBrush(); BitmapImage friendbit = new BitmapImage(new Uri(Path.Combine(Environment.CurrentDirectory, "Friendava" + num.ToString() + ".jpg"))); friendava.ImageSource = friendbit; Ellipse ava = new Ellipse(); ava.Height = 50; ava.Width = 50; ava.Fill = friendava; Grid.SetColumn(ava, 0); Grid.SetColumnSpan(ava, 2); Grid.SetRow(ava, 0); Grid.SetRowSpan(ava, 3); frgr.Children.Add(ava); } } num++; } })); }