سؤال

الضوابط التي ترث System.Web.UI.WebControls.WebControl لديك خاصية تسمى Font. النوع هو System.Web.Ui.WebControls.FontInfo.

عند العمل مع عناصر التحكم هذه في المصمم ، فإنه يكسر Font خاصية في خصائص متعددة مثل Font-Bold, Font-Italic, ، إلخ Font خاصية (لا Font-Bold, Font-Italic, ، إلخ).

كيف يمكن إعادة إنشاء هذا السلوك يدويًا عند إنشاء WebControls؟ على وجه التحديد ، ما مزيج من System.ComponentModel يمكن للسمات إظهار/إخفاء هذه الخصائص في Intellisense؟

هل كانت مفيدة؟

المحلول 3

الخاصية التي ترغب في توسيعها (Font في هذه الحالة) يجب أن يكون لها السمة System.ComponentModel.DesignerSerializationVisibility ضبط ل System.ComponentModel.DesignerSerializationVisibility.Content. هذا مفصل في الرابط التالي

System.componentModel.DesignerserializationVibility

نصائح أخرى

يجب أن تكون قادرًا على الوصول إلى BOLD و ITINIC وما إلى ذلك كخصائص منطقية:

http://msdn.microsoft.com/it-it/library/system.web.ui.webcontrols.fontinfo.aspx

  void Page_Load(object sender, EventArgs e)
  {
    // When the page loads, set the the myLabel Label control's FontInfo properties.
    // Note that myLabel.Font is a FontInfo object.

    myLabel.Font.Bold = true;
    myLabel.Font.Italic = false;
    myLabel.Font.Name = "verdana";
    myLabel.Font.Overline = false;
    myLabel.Font.Size = 10;
    myLabel.Font.Strikeout = false;
    myLabel.Font.Underline = true;

    // Write information on the FontInfo object to the myLabel label.
    myLabel.Text = myLabel.Font.ToString();

  }

يحدث الممتلكات تلقائيًا.

إذا كان لديك عنصر تحكم يحتوي على خاصية لها خصائص خاصة بها

public class ServerControl1 : WebControl
{
   public CompositeItem Composite { get; set; }

    public ServerControl1()
    {
        Composite = new CompositeItem();
    }
}

public class CompositeItem
{
    public bool ItemOne { get; set; }
    public string ItemTwo { get; set; }
    public int ItemThree { get; set; }
}

يمكنك استخدام بناء جملة الخط في ASPX ، وهذا يعني ذلك

<cc:ServerControl1 runat="server" ID="scOne" 
    Composite-ItemOne="true" Composite-ItemTwo ="stringx"/>

سيعمل كما هو متوقع. ومع ذلك ، فإن الإكمال التلقائي لا يعمل ، ولست متأكدًا من مزيج من System.ComponentModel مطلوب السمات لجعلها تتصرف مثل الخط.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top