Popupbutton with multiline textbox

Grids for WPF Forum

Posted 15 years ago by Balaram Barange
Version: 4.5.0487
Avatar
Hi Team,

I have Property Grid with one item "Description". I want to make their ValueTemplate like PopupButton with MultiLine TextBox to allow user to add lines of data.

I have created sample but need to dispaly text box from 2nd column of property grid with same Width. Because the Property Grid is inside Normal window which can be maximized and restore, so based on their TextBox width should be set.

Plase suggest How can I dynamically assign value to following two DPs?

popupButtonFactory.SetValue(PopupButton.PopupVerticalOffsetProperty, -21.0);
                popupButtonFactory.SetValue(PopupButton.PopupHorizontalOffsetProperty, -130.0);
Complete Code

private void InitMultiLineTextBox()
        {
            PropertyGridCategoryItem category = new PropertyGridCategoryItem();
            category.DisplayName = "Product Information";
            myGrid.Items.Add(category);

            PropertyGridPropertyItem item = new PropertyGridPropertyItem();
            item.DisplayName = "Description";
            ApplyMultiLineTextBoxDataTemplate(item);
            category.Accessors.Add(item);
        }

        private void ApplyMultiLineTextBoxDataTemplate(PropertyGridPropertyItem propertyGridItem)
        {
            try
            {
                // Popup Content Template -- Another framework element factory and DataTemplare for TextBoX
                DataTemplate popupDataTemplate = new DataTemplate();
                FrameworkElementFactory popupChildFactoryTxtBox = new FrameworkElementFactory(typeof(TextBox));
                popupChildFactoryTxtBox.SetValue(TextBox.WidthProperty, 130.0);
                popupChildFactoryTxtBox.SetValue(TextBox.HeightProperty, 60.0);
                popupDataTemplate.VisualTree = popupChildFactoryTxtBox;
                
                // Popup Button
                FrameworkElementFactory popupButtonFactory = new FrameworkElementFactory(typeof(PopupButton));
                popupButtonFactory.SetValue(PopupButton.DisplayModeProperty, PopupButtonDisplayMode.PopupOnly);
                popupButtonFactory.SetValue(PopupButton.PopupContentProperty, new object());
                popupButtonFactory.SetValue(PopupButton.PopupContentTemplateProperty, popupDataTemplate); // Assign Template
                popupButtonFactory.SetValue(PopupButton.HorizontalAlignmentProperty, HorizontalAlignment.Right);
                popupButtonFactory.SetValue(PopupButton.PopupVerticalOffsetProperty, -21.0);
                popupButtonFactory.SetValue(PopupButton.PopupHorizontalOffsetProperty, -130.0);
                

                DataTemplate dataTemplate = new DataTemplate(); // DataTemple
                dataTemplate.VisualTree = popupButtonFactory;

                PopupButton pb = new PopupButton();
                pb.FlowDirection = FlowDirection.RightToLeft;
                // Attach to Value Template
                propertyGridItem.ValueTemplate = dataTemplate;
            }
            catch (Exception ex)
            {
            }
        }

Comments (1)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can get the width of the cell by looking at the ActualWidth of the parent TreeListViewCell element. I'm not sure you would be able to bind that your TextBox thought, since the TextBox is in a Popup.

You might be better off implementing your own popup code, using a ToggleButton and Popup. That would allow you to set the Popup.Width/Height based on the TreeListViewCell (or a Grid that holds both the ToggleButton and Popup).


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.