Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In .NetCore project, Changes made in the Designer not being Serialized in the Designer.cs file. #11664

Open
Sekar47 opened this issue Jul 12, 2024 · 9 comments
Assignees
Labels
area-VSDesigner Windows Forms out-of-proc designer related issues 📭 waiting-author-feedback The team requires more information from the author
Milestone

Comments

@Sekar47
Copy link

Sekar47 commented Jul 12, 2024

Environment

Edition - Windows 11 Enterprise
Version - 23H2
OS build - 22631.3737
Visual Studio version - 17.10.4

.NET version

.Net 6,7,8

Did this work in a previous version of Visual Studio and/or previous .NET release?

No, it's not working in previous versions of netcore

Issue description

We are attempting to add items to a collection and serialize them in the designer class using the serializer class which inherits from CodeDomSerializer. However, this is not triggering whenever changes are made in the designer, resulting in the modifications not being serialized in the designer.cs file. Is this a limitation, or are there alternative solutions available?
CustomControl_Tab (2) 1.zip

Steps to reproduce

1.In the Designer, Drag and Drop the CustomTabControl from ToolBox.
2.Click on AddTabItem option from Smart tag, you can add the tab items but it is not available in designer.cs file.

Diagnostics

No response

@Sekar47 Sekar47 added the untriaged The team needs to look at this issue in the next triage label Jul 12, 2024
@elachlan elachlan added the area-VSDesigner Windows Forms out-of-proc designer related issues label Jul 12, 2024
@elachlan
Copy link
Contributor

@Olina-Zhang can your team please test?

@Olina-Zhang
Copy link
Member

I cannot repro it in my side, after clicking AddTabItem in SmartTag, the toolStripTabItems code is available in designer.cs file:
image

@elachlan elachlan added the 📭 waiting-author-feedback The team requires more information from the author label Jul 15, 2024
@JeremyKuhne JeremyKuhne added untriaged The team needs to look at this issue in the next triage and removed untriaged The team needs to look at this issue in the next triage labels Jul 16, 2024
@Sekar47
Copy link
Author

Sekar47 commented Jul 29, 2024

Hi @Olina-Zhang , But see the toolStripTabItem's doesn't added in any parent control such as Form1 or customTabControl1. this is the issue, Actually, I wanted a case like if I add toolStripTabItem via SmartTag of the customTabControl then it'll need to directly be added in the header of the customTabControl1. is there any solution for achieving this case?

@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback The team requires more information from the author label Jul 29, 2024
@Olina-Zhang
Copy link
Member

Hi @Sekar47, created a sample app, please take a look:
CustomControlSample.zip
image

@Sekar47
Copy link
Author

Sekar47 commented Sep 2, 2024

Hi @Olina-Zhang ,

Thank you for the sample code provided. please refer the attached sample. in my case, we are using CodeDomSerializer in our TabControlHeaderSerializer class to handle header serialization for the CustomTabControl.
CustomControl_Tab.2.1.zip

Could you please provide guidance or suggestions on how to properly use CodeDomSerializer in this scenario? Specifically, we are facing issues where changes made to the TabItem via the smart tag support are not reflected in the Designer.cs file.

Is there a recommended approach or best practices for using CodeDomSerializer to ensure that the designer updates correctly and reflects changes made in the UI? Any insights or examples on how to resolve this issue while continuing to use CodeDomSerializer would be greatly appreciated.

Thank you for your assistance.

@Tanya-Solyanik
Copy link
Member

@LeafShi1 - I took a quick look at the sample project, it seems that DesignerAction panel is implemented correctly, only the serializer is not discovered on

    [ToolboxItem(false)]
    [DesignerSerializer(typeof(TabControlHeaderSerializer), typeof(CodeDomSerializer))]
    public class CustomTabControlHeader : ToolStrip, IHeader

Could you or your team investigate if anything is missing in the project or if this is a designer bug. If this is a designer bug, please move the issue to the designer repo.

@Tanya-Solyanik Tanya-Solyanik removed the untriaged The team needs to look at this issue in the next triage label Oct 24, 2024
@Tanya-Solyanik Tanya-Solyanik added this to the VS release milestone Oct 24, 2024
@Epica3055
Copy link
Member

Epica3055 commented Nov 19, 2024

@Sekar47 this is a fragment of your code.

    public class ObservableList<T> : IList
    {
        #region Constructors
        public ObservableList()
        {
            list = new ArrayList();
        }
        
        #endregion

        #region Properties
        /// <summary>
        /// 
        /// </summary>
        public int Count
        {
            get { return this.List.Count; }
        }
       
        /// <summary>
        /// 
        /// </summary>
        protected IList List
        {
            get { return this; }
        }

I think you might want to replace

        protected IList List
        {
            get { return this; }
        }

with

        protected IList List
        {
            get { return list; }
        }

This is the generated code after the change.

        private void InitializeComponent()
        {
            customTabControl1 = new CustomTabControl();
            toolStripTabItem1 = new ToolStripTabItem();
            toolStripTabItem2 = new ToolStripTabItem();
            SuspendLayout();
            // 
            // customTabControl1
            // 
            customTabControl1.Header.AddMainItem(toolStripTabItem1);
            customTabControl1.Header.AddMainItem(toolStripTabItem2);
            customTabControl1.Location = new System.Drawing.Point(299, 104);
            customTabControl1.Name = "customTabControl1";
            customTabControl1.Size = new System.Drawing.Size(150, 150);
            customTabControl1.TabIndex = 0;
            // 
            // toolStripTabItem1
            // 
            toolStripTabItem1.Name = "toolStripTabItem1";
            toolStripTabItem1.Size = new System.Drawing.Size(23, 23);
            // 
            // toolStripTabItem2
            // 
            toolStripTabItem2.Name = "toolStripTabItem2";
            toolStripTabItem2.Size = new System.Drawing.Size(23, 23);
            // 
            // Form1
            // 
            AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
            AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            ClientSize = new System.Drawing.Size(700, 422);
            Controls.Add(customTabControl1);
            Name = "Form1";
            Text = "Form1";
            ResumeLayout(false);
        }

        #endregion

        private CustomTabControl customTabControl1;
        private ToolStripTabItem toolStripTabItem1;
        private ToolStripTabItem toolStripTabItem2;

do you think this is the expected result?

@Tanya-Solyanik Tanya-Solyanik added the 📭 waiting-author-feedback The team requires more information from the author label Nov 19, 2024
@SekarSivalingam
Copy link

Hi @Epica3055 ,

Thank you for your response and suggestions. We implemented the recommended change to the ObservableList class, but unfortunately, the issue persists. Adding ToolStripTabItem via the SmartTag does not serialize properly into the Header of customTabControl1 in the Designer.cs file.

We’ve attached an updated sample and a video demonstration for clarity. Could you kindly review and provide further guidance on resolving this issue or suggest alternative approaches to achieve this expecting behavior?
CustomControl_Tab.2.1 (3).zip

@Epica3055
Copy link
Member

During my investigation, I found another problem that could lead serialization failure.
Image

There actually are two System.CodeDom.dll, so there will be a conflict.

During the process, somehow the System.CodeDom.dll referenced by Microsoft.WinForms.Designer.SDK disappeared, and the desired code was generated.
Image

            customTabControl1.Header.AddMainItem(toolStripTabItem1);
            customTabControl1.Header.AddMainItem(toolStripTabItem2);

But I still don't know why it disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VSDesigner Windows Forms out-of-proc designer related issues 📭 waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

No branches or pull requests

8 participants