
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?Complete Code
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);
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)
{
}
}