示例#1
0
        void OnWrapOptionAppBarButtonClick(object sender, RoutedEventArgs args)
        {
            // Create dialog
            WrapOptionsDialog wrapOptionsDialog = new WrapOptionsDialog
            {
                TextWrapping = txtbox.TextWrapping
            };

            // Bind dialog to TextBox
            Binding binding = new Binding
            {
                Source = wrapOptionsDialog,
                Path   = new PropertyPath("TextWrapping"),
                Mode   = BindingMode.TwoWay
            };

            txtbox.SetBinding(TextBox.TextWrappingProperty, binding);

            // ダイアログを Flyoutへ変更
            Flyout flyout = new Flyout()
            {
                Content   = wrapOptionsDialog,
                Placement = FlyoutPlacementMode.Top
            };

            flyout.ShowAt(sender as FrameworkElement);
        }
        void OnWrapOptionAppBarButtonClick(object sender, RoutedEventArgs args)
        {
            // Create dialog
            WrapOptionsDialog wrapOptionsDialog = new WrapOptionsDialog
            {
                TextWrapping = txtbox.TextWrapping
            };

            // Bind dialog to TextBox
            Binding binding = new Binding
            {
                Source = wrapOptionsDialog,
                Path   = new PropertyPath("TextWrapping"),
                Mode   = BindingMode.TwoWay
            };

            txtbox.SetBinding(TextBox.TextWrappingProperty, binding);

            // Create popup
            Popup popup = new Popup
            {
                Child = wrapOptionsDialog,
                IsLightDismissEnabled = true
            };

            // Adjust location based on content size
            wrapOptionsDialog.Loaded += (dialogSender, dialogArgs) =>
            {
                // Get Button location relative to screen
                Button btn = sender as Button;
                Point  pt  = btn.TransformToVisual(null).TransformPoint(new Point(btn.ActualWidth / 2,
                                                                                  btn.ActualHeight / 2));

                popup.HorizontalOffset = pt.X - wrapOptionsDialog.ActualWidth / 2;

                popup.VerticalOffset = this.ActualHeight - wrapOptionsDialog.ActualHeight
                                       - this.BottomAppBar.ActualHeight - 48;
            };

            // Open the popup
            popup.IsOpen = true;
        }