How can I update the Name of a Petrel Window?

情到浓时终转凉″ 提交于 2019-12-20 07:53:10

问题


I am trying to update the Name/Display Name of a Petrel Window after the Save event.

I implemented my own NameInfo class that inherits from the NameInfo abstract class.

 public class MyNameInfo : NameInfo
    {
        private string name = string.Empty;
        private string displayName = string.Empty;
        private string typeName = string.Empty;

        public override bool CanChangeName
        {
             get { return true; } //I return true so I can change the name at runtime.
        }
        //Rest of the class implementation
     }

My DisplayName, Name and TypeName has to be the same, so when the name is changed my code is:

public override string Name
        {
            get { return this.name; }
            set
            {
                name = value;
                displayName = value;
                typeName = value;
                OnNameChanged(this);
            }
        }

I change the name of my window on the "Saved" event of the DataSourceManager:

DataManager.DataSourceManager.Saved += OnSave;

The code I use to update the name is:

if(NameInfo.CanChangeName)
     NameInfo.Name = NewName;

But when I change the name, it appears updated only in the tree of the Windows window.

The Name of my window shows the old name.

I dont know what else I have to do to achieve what I want.

My Window is a custom window

public class MyCustomWindow : ToggleWindow, INameInfoSource, IDeletable 
{

Is there a way to update the Window Name itself?

Do I have to subscribe my "MyCustomWindow" to some event and I am not doing it?

I will really appreciate any help you can offer me!


回答1:


How do you create your NameInfo in your custom window? You need to pass the custom window object to MyNameInfo such that you can call OnNameChanged(window) on the custom window object. Here's an example:

private MyNameInfo nameInfo = null;
public NameInfo NameInfo
{
  get
  {
    if (null == nameInfo)
    {
      nameInfo = new MyNameInfo(this);
    }
    return nameInfo;
  }
}

And then in your setter of the Name property of MyNameInfo,

set
{
   name = value;
   displayName = value;
   typeName = value;
   OnNameChanged(this.window);
}


来源:https://stackoverflow.com/questions/17117029/how-can-i-update-the-name-of-a-petrel-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!