private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Get backing visual from shadow container and interop compositor _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer); _compositor = _shadowContainer.Compositor; // Get CompositionImage, its sprite visual _image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer); _imageVisual = _image.SpriteVisual; // Load mask asset onto surface using helpers in SamplesCommon _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White); // Create surface brush for mask CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush(); mask.Surface = _imageMaskSurface.Surface; // Get surface brush from composition image CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush; // Create mask brush for toggle mask functionality _maskBrush = _compositor.CreateMaskBrush(); _maskBrush.Mask = mask; _maskBrush.Source = source; // Initialize toggle mask _isMaskEnabled = false; }
private void collectionsGridView_SelectionChanged(object sender, SelectionChangedEventArgs e) { GridView collectionGridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(CollectionsHubSection); GridView recentlyOpenedGridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(RecentlyOpenedHubSection); BottomAppBar.IsOpen = collectionGridView.SelectedItems.Count > 0 || recentlyOpenedGridView.SelectedItems.Count > 0; }
private async void DeleteAppBarButton_Click(object sender, RoutedEventArgs e) { LoadingRing.Visibility = Visibility.Visible; GridView collectionGridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(CollectionsHubSection); foreach (CollectionView collectionView in collectionGridView.SelectedItems) { CollectionTile collectionTile = collectionView.Tile; CollectionTiles.Remove(collectionTile); CollectionViews.Remove(collectionView); StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFolder collectionsFolder = (StorageFolder)await localFolder.TryGetItemAsync("Collections"); if (null != collectionsFolder) { StorageFolder collectionFolder = await collectionsFolder.TryGetItemAsync(collectionTile.Title) as StorageFolder; await collectionFolder.DeleteAsync(); } } GridView recentlyOpenedGridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(RecentlyOpenedHubSection); foreach (ComicTile comicTile in recentlyOpenedGridView.SelectedItems) { ComicTiles.Remove(comicTile); await comicTile.Folder.DeleteAsync(); } LoadingRing.Visibility = Visibility.Collapsed; }
internal static void Show(string photo, object itemSource, Func <object, bool, Uri> photoGetter, Thickness margin, UIElement page) { if (_viewerInstance != null) { throw new InvalidOperationException("Already displaying a photoviewer popup"); } _hostGrid = VisualTreeHelperExtensions.GetFirstDescendantOfType <Grid>(page); if (_hostGrid != null) { _viewerInstance = new ImagePopupViewer(photoGetter, photo); // dialog needs to span all rows in the grid _viewerInstance.SetValue(Grid.RowSpanProperty, (_hostGrid.RowDefinitions.Count > 0 ? _hostGrid.RowDefinitions.Count : 1)); _viewerInstance.SetValue(Grid.ColumnSpanProperty, (_hostGrid.ColumnDefinitions.Count > 0 ? _hostGrid.ColumnDefinitions.Count : 1)); _hostGrid.Children.Add(_viewerInstance); _viewerInstance.ItemsSource = itemSource; } else { throw new ArgumentException("can't find a top level grid"); } }
private void Tb_LostFocus2(object sender, RoutedEventArgs e) { //if textbox is the last in the stackpanel then action is done so remove TextBox tb = sender as TextBox; FormEntry entry = tb.Tag as FormEntry; //if (entry.var2Type == 1) //{ // int weight; // bool bFailed = false; // if (!Int32.TryParse(tb.Text, out weight)) // bFailed = true; // if (weight < 10 || weight > 85) // bFailed = true; // if (bFailed) // { // MessageBox.Show("invalid weight"); // return ; // } //} Debug.WriteLine(string.Format("Tb_LostFocus2 {0} {1} ", tb.Tag, tb.Text)); var sp = VisualTreeHelperExtensions.FindAncestor <StackPanel>(tb); var grid = VisualTreeHelperExtensions.FindAncestor <Grid>(sp); int index = sp.Children.IndexOf(tb); if (index + 1 == sp.Children.Count) { removeline(entry); // CheckForFinish(block); } // rootGrid.Children.Remove(sptest); }
#pragma warning disable 1998 private async Task Build() #pragma warning restore 1998 { this.RootElements.Clear(); var rootElement = VisualTreeHelperExtensions.GetRealWindowRoot(); if (rootElement != null) { var ancestors = rootElement.GetAncestors(); if (ancestors != null) { var newRoot = ancestors.OfType <UIElement>().LastOrDefault(); if (newRoot != null) { rootElement = newRoot; } } this.RootElements.Add(new DependencyObjectViewModel(this, null, rootElement)); } foreach (var popup in VisualTreeHelper.GetOpenPopups(Window.Current)) { this.RootElements.Add(new DependencyObjectViewModel(this, null, popup)); } }
private void ThumbnailList_Click(object sender, ItemClickEventArgs e) { GridView gridView = (GridView)sender; GridViewItem item = (GridViewItem)gridView.ContainerFromItem(e.ClickedItem); CompositionImage image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(item); // We are about to transition to a new page. Cancel any outstanding transitions. if (_currentTransition != null) { if (!_currentTransition.Completed) { _currentTransition.Cancel(); } _currentTransition = null; } DetailsInfo info; info.thumbanil = (Thumbnail)e.ClickedItem; // Setup the new transition and trigger the navigation ConnectedTransition transition = new ConnectedTransition(); transition.Initialize(Frame, image, info); Frame.Navigate(typeof(CustomConnectedAnimationDetail), transition); }
private void ImageList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ImageList.SelectedItem != null) { ListViewItem item = (ListViewItem)ImageList.ContainerFromItem(ImageList.SelectedItem); Uri imageSource = _imageUriGetterFunc(item.Content, true); if (_crossFadeBatch == null) { // Save the previous image for a cross-fade _previousSurfaceBrush.Surface = BackgroundImage.SurfaceBrush.Surface; _previousSurfaceBrush.CenterPoint = BackgroundImage.SurfaceBrush.CenterPoint; _previousSurfaceBrush.Stretch = BackgroundImage.SurfaceBrush.Stretch; // Load the new background image BackgroundImage.ImageOpened += BackgroundImage_ImageChanged; } // Update the images BackgroundImage.Source = imageSource; PrimaryImage.Source = imageSource; if (!_transition.Completed) { _transition.Cancel(); } // Kick off a connected animation to animate from it's current position to it's new location CompositionImage image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(item); _transition.Initialize(this, image, null); _transition.Start(this, PrimaryImage, null, null); } }
private static void OnOpened(object sender, EventArgs e) { var popup = sender as Popup; if (popup != null) { var target = popup.PlacementTarget as FrameworkElement; if (target != null) { if (popup.Child != null) { var root = VisualTreeHelperExtensions.FindTopLevelParent(popup.Child) as Visual; if (root != null) { var realPosition = root.PointToScreen(new Point(0d, 0d)); var calculatedPosition = target.PointToScreen(new Point(0d + popup.HorizontalOffset, target.ActualHeight - popup.VerticalOffset)); var isDefaultHorizontalPosition = Math.Abs(realPosition.X - calculatedPosition.X) < double.Epsilon; var isDefaultVerticalPosition = Math.Abs(realPosition.Y - calculatedPosition.Y) < double.Epsilon; SetIsDefaultHorizontalPosition(popup, isDefaultHorizontalPosition); SetIsDefaultVerticalPosition(popup, isDefaultVerticalPosition); } } } } }
protected override void Invoke(object parameter) { var args = parameter as RoutedEventArgs; if (args == null) { return; } var tabitem = VisualTreeHelperExtensions.FindAncestor <TabItem>(args.OriginalSource as DependencyObject); if (tabitem == null) { return; } var tabcontrol = VisualTreeHelperExtensions.FindAncestor <TabControl>(tabitem); if (tabcontrol == null) { return; } IRegion region = RegionManager.GetObservableRegion(tabcontrol).Value; if (region == null) { return; } //tabcontrol.Items.Remove(tabitem.Content); RemoveItemFromRegion(tabitem.Content, region); }
/// <summary> /// 返回最顶层的元素的在dragpoint型坐标。 /// Returns the top-most element of the given type /// at the DragPoint coordinates. /// </summary> /// <typeparam name="T">The type of the element to be returned.返回元素的类型。</typeparam> public T GetElement <T>(System.Windows.Point dragPoint) where T : System.Windows.FrameworkElement { // 注意:这不是要工作在WinForms!你可以使用扩展方法,将发现根视觉相对第一个参数(这个)。 // NOTE: This is not going to work in WinForms! You could use the extension method that will find to root visual // relatively to the first argument (this). return(VisualTreeHelperExtensions.GetElementsInScreenCoordinates <T>(dragPoint).FirstOrDefault()); }
async void PublicationsTreeView_ScrollableItemSelected(object sender, EventArgs e) { if (DataContext is FormationChoiceViewModel vm) { var syncTreeViewItem = VisualTreeHelperExtensions.FindLastChild <TreeViewItemAdv>(PublicationsTreeView, i => { if (i is TreeViewItemAdv item) { return(item.IsMouseOver); } return(false); }); if (syncTreeViewItem?.DataContext is ProjectDir folder && folder.Id != -1) { if (folder.Id != -1) { folder.IsExpanded = !folder.IsExpanded; } vm.CurrentNode = null; } else if (syncTreeViewItem?.DataContext is Procedure process) { if (process.ProcessId != (vm.TrainingPublication?.ProcessId ?? 0)) { vm.CurrentNodeIsChanging = true; await vm.OnCurrentNodeChanged(process); PublicationsTreeView.SelectedTreeItem = vm.CurrentNode; } } else { vm.CurrentNode = null; } }
//TODO: .NET40 public async void Close() { if (IsClosing) { return; } IsClosing = true; RaiseEvent(new RoutedEventArgs(NotificationCloseInvokedEvent)); await Task.Delay(_closingAnimationTime); RaiseEvent(new RoutedEventArgs(NotificationClosedEvent)); var currentWindow = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.Title.Equals("ToastWindow")); if (currentWindow == null) { return; } var notificationCount = VisualTreeHelperExtensions.GetActiveNotificationCount(currentWindow); if (notificationCount == 0) { currentWindow?.Hide(); } }
private void OnDropDownOpened(object sender, EventArgs e) { if (HasSubmenu) { Mouse.Capture((IInputElement)VisualTreeHelperExtensions.FindTopLevelParent(Submenu), CaptureMode.SubTree); OnDropDownOpened(e); } }
/// <summary> /// Unpins the item from the StartScreen and shows confirmation popup /// at the specified placement, relative to the sourceElement /// </summary> /// <param name="tileId"></param> /// <param name="shortName"></param> /// <param name="displayName"></param> /// <param name="logo"></param> /// <param name="sourceElement"></param> /// <param name="placement"></param> /// <returns></returns> public static async Task <bool> UnpinItem(string tileId, FrameworkElement sourceElement, Placement placement) { var tileToDelete = new SecondaryTile(tileId); bool unpinSuccess = await tileToDelete.RequestDeleteForSelectionAsync(VisualTreeHelperExtensions.GetElementRect(sourceElement), placement); return(unpinSuccess); }
private void RootGrid_Tapped(object sender, TappedRoutedEventArgs e) { Button ancestor = VisualTreeHelperExtensions.GetFirstAncestorOfType <Button>((DependencyObject)e.OriginalSource); if (ancestor == null) { ShowEffectPropertyFlyout(); } }
public void FindDescendantsForNullParamTest() { // Act & Verify Assert.ThrowsException <ArgumentException>(() => { var descendants = VisualTreeHelperExtensions .FindDescendants <Panel>(null) .ToList(); }); }
private void ClearAppBarButton_Click(object sender, RoutedEventArgs e) { GridView gridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(CollectionsHubSection); gridView.SelectedItem = null; GridView recentlyOpenedGridView = VisualTreeHelperExtensions.GetFirstDescendantOfType <GridView>(RecentlyOpenedHubSection); recentlyOpenedGridView.SelectedItem = null; }
private void OnDropDownOpened(object sender, EventArgs e) { if (HasSubmenu) { // HasSubmenu ensures that Submenu isn't null Contract.Assume(Submenu != null); Mouse.Capture((IInputElement)VisualTreeHelperExtensions.FindTopLevelParent(Submenu), CaptureMode.SubTree); OnDropDownOpened(e); } }
private void Navigate(DependencyObject originalSource) { var item = VisualTreeHelperExtensions.FindAncestor <TreeViewItem>(originalSource); if (item != null && item.Tag != null) { var navigatePath = item.Tag.ToString(); _regionManager.RequestNavigate(RegionNames.MAIN_REGION, navigatePath); } }
private async void Load() { await Task.Run(() => { string result = API.GetAllTable(); stuff = JsonConvert.DeserializeObject(result); if (result == "") { return; } this.Dispatcher.Invoke(() => { foreach (var item in stuff) { Tables.Add(new Model.Table() { id = item._id, number = item.number, numberOfSeat = item.numberOfSeat, type = item.type, status = item.status, note = item.note, customer = new Customer() { fullName = item.customer.fullName, phone = item.customer.phone } }); } ; }); }); await Task.Run(() => { Thread.Sleep(1000); this.Dispatcher.Invoke(() => { for (int i = 0; i < Tables.Count; i++) { if (Tables[i].type == "standard") { ListViewItem lvi1 = ListViewTable.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem; var cp1 = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi1); var dt1 = cp1.ContentTemplate as DataTemplate; var rt1 = (Grid)dt1.FindName("TicketType", cp1); rt1.Background = Brushes.Blue; } } ; }); }); }
/// <summary> /// Plays the moving coin animation. /// </summary> public void PlayMovingCoinAnimation() { var rootGrid = VisualTreeHelperExtensions.FindDescendants <Grid>(this) .FirstOrDefault(g => g.Name == "RootGrid"); if (rootGrid != null) { var animation = (Storyboard)rootGrid.Resources["movingCoinAnimation"]; animation.Begin(); } }
/// <summary> /// Appelé lorsque la CheckBox est cochée ou décochée. /// </summary> /// <param name="sender">La source.</param> /// <param name="e">Les données de l'évènement.</param> private void cb_Checked(object sender, RoutedEventArgs e) { var cb = (CheckBox)sender; var dataGrid = VisualTreeHelperExtensions.TryFindParent <DataGrid>(cb); if (dataGrid != null) { Dispatcher.BeginInvoke((Action <DataGrid>)(dg => dg.CommitEdit(DataGridEditingUnit.Row, true)), dataGrid); } }
private ContentControl GenerateHintItem(Hint hint) { var container = new ContentControl(); var element = VisualTreeHelperExtensions.GetChildByName(Window.Current.Content as Control, hint.PlacementTargetName); Rect elementRect = VisualTreeHelperExtensions.GetElementRect(element); PlacementMode placement = hint.Placement; container.Width = hint.Width != 0 ? hint.Width : 50; container.Height = hint.Height != 0 ? hint.Height : 50; container.Content = hint.Content; double left = 0; double top = 0; Style style = null; switch (placement) { case PlacementMode.Bottom: { left = elementRect.Left + elementRect.Width / 2 - container.Width / 2; top = elementRect.Top + elementRect.Height; style = this.BottomHintStyle; } break; case PlacementMode.Top: { left = elementRect.Left + elementRect.Width / 2 - container.Width / 2; top = elementRect.Top - container.Height; style = this.TopHintStyle; } break; case PlacementMode.Left: { left = elementRect.Left - container.Width; top = elementRect.Top + elementRect.Height / 2 - container.Height / 2; style = this.LeftHintStyle; } break; case PlacementMode.Right: { left = elementRect.Left + elementRect.Width; top = elementRect.Top + elementRect.Height / 2 - container.Height / 2; style = this.RightHintStyle; } break; } container.Margin = new Thickness(left, top, 0, 0); container.SetValue(ToolTip.StyleProperty, style); return container; }
private void ApplyTemplateInternal() { if (Template != null) { if (_popup != null) { _popup.Child = null; if (Submenu != null) { var popupRootInstance = VisualTreeHelperExtensions.FindTopLevelParent(Submenu); if (popupRootInstance != null) { var presentationFramework = Assembly.GetAssembly(typeof(System.Windows.Window)); if (presentationFramework != null) { var popupRoot = presentationFramework.GetType("System.Windows.Controls.Primitives.PopupRoot"); if (popupRoot != null) { var popupRootChild = popupRoot.GetProperty("Child", BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.NonPublic); if (popupRootChild != null) { popupRootChild.SetValue(popupRootInstance, null, null); } } } } } _popup.Closed -= OnDropDownClosed; _popup.Opened -= OnDropDownOpened; _popup.CustomPopupPlacementCallback = null; } // Bug in Code Contracts static checker: Template is already checked to null Contract.Assume(Template != null); _popup = Template.FindName(PopupName, this) as Popup; if (_popup == null) { Trace.TraceError(PopupName + " not found."); } else { _popup.CustomPopupPlacementCallback = PlacePopup; _popup.Opened += OnDropDownOpened; _popup.Closed += OnDropDownClosed; if (Submenu != null) { _popup.Child = Submenu; } } } }
/// <summary> /// Pins the item to the StartScreen and shows confirmation popup /// at the specified placement, relative to the sourceElement /// </summary> /// <param name="tileId"></param> /// <param name="shortName"></param> /// <param name="displayName"></param> /// <param name="logo"></param> /// <param name="sourceElement"></param> /// <param name="placement"></param> /// <returns></returns> public static async Task <bool> PinItem(string tileId, string shortName, string displayName, Uri logo, FrameworkElement sourceElement, Placement placement) { string arguments = tileId; var newTile = new SecondaryTile(tileId, displayName, arguments, logo, TileSize.Square150x150); newTile.VisualElements.ForegroundText = ForegroundText.Dark; newTile.VisualElements.ShowNameOnSquare150x150Logo = true; bool pinSuccess = await newTile.RequestCreateForSelectionAsync(VisualTreeHelperExtensions.GetElementRect(sourceElement), placement); return(pinSuccess); }
private void NavigateToGame() { var mainWindow = VisualTreeHelperExtensions.FindParent <MainWindow>(this); if (mainWindow == null) { return; } var mainViewModel = (MainViewModel)mainWindow.DataContext; mainViewModel.NavigateViewCommand.Execute("Game"); }
private void ThumbnailList_Loaded(object sender, RoutedEventArgs args) { if (_currentTransition != null) { DetailsInfo info = (DetailsInfo)_currentTransition.Payload; GridViewItem item = (GridViewItem)ThumbnailList.ContainerFromItem(info.thumbanil); CompositionImage image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(item); ScrollViewer scrollViewer = VisualTreeHelperExtensions.GetFirstDescendantOfType <ScrollViewer>(ThumbnailList); // Kick off the transition now that the page has loaded _currentTransition.Start(MyGrid, image, scrollViewer, ThumbnailList); } }
private static void OnIsApplicationBarHostChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var host = obj as Decorator; if (host != null) { var window = VisualTreeHelperExtensions.FindParent <System.Windows.Window>(host); if (window != null) { var applicationBar = GetApplicationBar(window); host.Child = BooleanBoxingHelper.Unbox(e.NewValue) ? applicationBar : null; } } }
private void _tb_Loaded(object sender, RoutedEventArgs e) { if (_parent == null) { _parent = VisualTreeHelperExtensions.TryFindParent <FrameworkElement>(_tb); if (_parent == null) { throw new InvalidOperationException("Parent introuvable"); } } _parent.SizeChanged += cell_SizeChanged; Update(); }