在设计主机中更新innerproperties样式类 [英] Update innerproperties style class in design host

查看:58
本文介绍了在设计主机中更新innerproperties样式类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我正在创建一个自定义菜单脚本控件,我在设计主机中遇到了我的设计器类的问题。我刚刚开始创建我的控件,所以我没有太多,但我确实添加了一些属性并构建了一个设计器,因此我的属性可以在设计时更新。



要添加我控制的样式我添加了2个样式作为内部属性我还创建了一个Test属性,以便在我更改智能任务时查看它是否在设计主机中更新。 Test属性会像它应该更新,但内部属性不是这样,我必须遗漏一些东西。



这就是我得到的。



HTML页面

Hello

I'm creating a custom Menu scriptcontrol and I'm facing a problem in the design host with the my designer class. I just started creating my control so I don't have much but I did add some properties and building a designer so my properties can be updated in designtime.

To add styles to my control I have added 2 styles as an innerproperty also I made a Test property to see if it gets updated in the design host when I change in my Smart Task. The Test property gets updated like it should but the innerproperties not so I must be missing something.

This is what I got.

the HTML page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="Scriptmanager1"></asp:ScriptManager>
        <nav>
            <quyodev:WebMenu  runat="server" ID="MenuTest" Testen="">
                <StaticMenuStyle CssClass="Test" BackColor="Blue" Width="600px" Height="30px" />
                <StaticMenuHoverStyle BackColor="Yellow" Width="600px" Height="30px" />
            </quyodev:WebMenu>
        </nav>
    </form>
</body>
</html>





我遇到问题的部分属性。

这些属性未在设计主机中更新。



Part of the properties which I'm having problems with.
those properties are not updated in the design host.

[PersistenceMode(PersistenceMode.InnerProperty)]
public Style StaticMenuStyle
{
    get
    {
        if (_staticMenuStyle == null)
        {
            _staticMenuStyle = new Style();
            if (IsTrackingViewState)
                ((IStateManager)_staticMenuStyle).TrackViewState();
        }
        return _staticMenuStyle;
    }
}

[PersistenceMode(PersistenceMode.InnerProperty)]
public Style StaticMenuHoverStyle
{
    get
    {
        if (_staticMenuHoverStyle == null)
        {
            _staticMenuHoverStyle = new Style();
            if (IsTrackingViewState)
                ((IStateManager)_staticMenuHoverStyle).TrackViewState();
        }
        return _staticMenuHoverStyle;
    }
}





这是我的设计师课程。



Here is my designer class.

using QuyoDev.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace QuyoDev.Web.UI.Design.WebControls
{
    internal class WebMenuDesigner : ControlDesigner
    {
        private WebMenu _control;
        private ViewTypes _view;

        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            _control = (WebMenu)component;
        }

        public ViewTypes View
        {
            get { return _view; }
            set { _view = value; }
        }

        public Style SelectedStyle
        {
            get { return (Style)TypeDescriptor.GetProperties(_control)[string.Format("{0}Style", View)].GetValue(_control); }
            set { TypeDescriptor.GetProperties(_control)[string.Format("{0}Style", View)].SetValue(_control, value); UpdateDesignTimeHtml(); }
        }

        public override DesignerActionListCollection ActionLists
        {
            get
            {
                DesignerActionListCollection actionLists = new DesignerActionListCollection();
                actionLists.AddRange(base.ActionLists);
                actionLists.Add(new ActionList(this));
                return actionLists;
            }
        }

        public override string GetDesignTimeHtml()
        {
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
            htmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, SelectedStyle.CssClass);
            htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, SelectedStyle.GetStyleAttributes(null).Value);
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Div);
            //ChildItems
            htmlWriter.RenderEndTag();
            return stringWriter.ToString();
        }

        public enum ViewTypes
        {
            StaticMenu,
            StaticMenuHover
        }

        private class ActionList : DesignerActionList
        {
            private WebMenuDesigner _parent;

            public ActionList(WebMenuDesigner parent) : base(parent.Component)
            {
                _parent = parent;
            }

            public ViewTypes View
            {
                get { return _parent.View; }
                set
                {
                    _parent.View = value;
                    _parent.UpdateDesignTimeHtml();
                }
            }

            public string CssClass
            {
                get { return TypeDescriptor.GetProperties(_parent.SelectedStyle)["CssClass"].GetValue(_parent.SelectedStyle).ToString(); }
                set
                {
                    TypeDescriptor.GetProperties(_parent.SelectedStyle)["CssClass"].SetValue(_parent.SelectedStyle, value);
                    _parent.UpdateDesignTimeHtml();
                }
            }

            public Color BackColor
            {
                get { return (Color)TypeDescriptor.GetProperties(_parent.SelectedStyle)["BackColor"].GetValue(_parent.SelectedStyle); }
                set
                {
                    TypeDescriptor.GetProperties(_parent.SelectedStyle)["BackColor"].SetValue(_parent.SelectedStyle, value);
                    _parent.UpdateDesignTimeHtml();
                }
            }

            public string TestAction
            {
                get { return TypeDescriptor.GetProperties(_parent.Component)["Testen"].GetValue(_parent.Component).ToString(); }
                set { TypeDescriptor.GetProperties(_parent.Component)["Testen"].SetValue(_parent.Component, value); }
            }

            public override DesignerActionItemCollection GetSortedActionItems()
            {
                DesignerActionItemCollection items = new DesignerActionItemCollection();
                items.Add(new DesignerActionHeaderItem("Appearance"));
                items.Add(new DesignerActionPropertyItem("View", "View:", "Appearance", "Change webmenu display"));
                items.Add(new DesignerActionPropertyItem("TestAction", "Test:", "Appearance", "Do Test"));
                items.Add(new DesignerActionHeaderItem("Style"));
                items.Add(new DesignerActionPropertyItem("CssClass", "CssClass:", "Style", "Change CSS class"));
                items.Add(new DesignerActionPropertyItem("BackColor", "BackColor:", "Style", "Change background color"));
                return items;
            }
        }
    }
}





我尝试了什么:



创建一个Test属性,看看它是否在设计主机中得到更新,但这很有效。



What I have tried:

Created a Test property to see if this gets updated in the design Host but this works perfect.

推荐答案

我能够通过添加底层代码来解决我的解决方案



I was able to resolve my solution with adding underlaying code

public void UpdateSelectedStyle(string property, object value)
{
     Style style = new Style();
     style.CopyFrom(SelectedStyle);
     TypeDescriptor.GetProperties(style)[property].SetValue(style, value);
     SelectedStyle = style;
     UpdateDesignTimeHtml();
}


这篇关于在设计主机中更新innerproperties样式类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆