设计时的用户控制属性

发布于 2024-08-26 19:54:42 字数 461 浏览 3 评论 0原文

我正在 Visual Studio 2008 中测试一个简单的用户控件:一个名为 Wrapper 的面板,其中包含一些控件。 Visual Studio 可以在设计时处理这个问题吗?

public partial class TestControl : System.Web.UI.UserControl
{
    [Description("Css class of the div around the control.")]
    [CssClassProperty]
    public string CssClass
    {
        get { return Wrapper.CssClass; }
        set { Wrapper.CssClass = value; }
    }
}

设置 CssClass 属性时,它不会在设计时更新面板的 css。我是不是希望太多了?

I'm testing a simple User Control in Visual Studio 2008: A Panel named Wrapper with some controls inside. Can Visual Studio handle this at design time?

public partial class TestControl : System.Web.UI.UserControl
{
    [Description("Css class of the div around the control.")]
    [CssClassProperty]
    public string CssClass
    {
        get { return Wrapper.CssClass; }
        set { Wrapper.CssClass = value; }
    }
}

When setting the CssClass property, it doesn't update the css of the Panel at design time. Am I hoping for too much?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撑一把青伞 2024-09-02 19:54:42

我认为你必须检查父级并投射它

if(this.Parent is Panel)
{
   ((Panel)this.Parent).CssClass = value;
}

或类似的。

I think you would have to check the parent and cast it

if(this.Parent is Panel)
{
   ((Panel)this.Parent).CssClass = value;
}

Or similar.

不必在意 2024-09-02 19:54:42

在 VS IDE 中设计页面可能是一件令人头疼的事情,因为当内容通过代码隐藏或整个站点继承的全局页面标头(例如,通过子类化)加载时,IDE 不知道 ASPX 加载的 CSS页面。)这使得使用 VS IDE 来设计这些子页面/控件/等变得非常困难。将 CSS 插入到子文档或控件中不是一个选项,因为编译后的页面通常会包含对样式表,并且很可能在声明之前提供第一个引用。

这是让 Visual Studio 在 IDE 中使用任意 CSS 的一种方法,这样您就可以使用设计者不知道所提供的页面中存在的 CSS 来设计控件。因此,您可以使用它使 CSS 在编辑器中的设计时可用,但在调试或运行时不可用。我非常确定这也适用于您的场景。

插入此内容:

<% 
#If 0 Then
%>    
    <link rel='stylesheet' href='mycss.css' type='text/css' />        
<%
#End If
%>

这将仅在 IDE 的 html 设计器中加载样式表。

Designing pages can be a big headache in the VS IDE as the IDE is unaware of CSS loaded by your ASPX when that content is loaded through code-behind or by a global page header that your entire site inherits (for example, through sub-classing of PAGE.) It makes using the VS IDE quite difficult for designing those sub-pages / controls / etc. Inserting the CSS into your sub-document or control is not an option, because the compiled page will often then include duplicate references to the style sheet, and quite possibly serving the first reference even before the declaration.

Here is one way to get Visual Studio to use arbitrary CSS in the IDE getting past this, so you can design controls using css that the designer is unaware exists in the served page. So you can use this to make CSS available at design time in the editor, but NOT at debug or run-time. I'm quite certain this will work in your scenario as well.

Insert this:

<% 
#If 0 Then
%>    
    <link rel='stylesheet' href='mycss.css' type='text/css' />        
<%
#End If
%>

This will load your style sheet only in the html designer of the IDE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文