SmartClient Software factory中的Composite UI Application Block(Cab)技術瞭解(六):SmartPartInfo

SmartPartInfo描述和實例

 

       界面顯示時有各種屬性,而對這些屬性的控制在SCSF中都是通過SmartPartInfo來進行控制,這樣可以通過視圖與不同的SmartPartInfo來控制視圖的不同表現效果。

1.         在上面的項目中增加一個視圖infoView,同時需要該視圖繼承一個IsmartPartInfoProvider的類,該類實現一個GetSmartPartInfo的方法,用於給容器調用。

  [SmartPart]

    public partial class infoView : UserControl, IinfoView, ISmartPartInfoProvider

    {

      。。。

        #region ISmartPartInfoProvider 成員

        public ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)

        {

            ISmartPartInfo spi = null;

            if (smartPartInfoType.IsAssignableFrom(typeof(WindowSmartPartInfo)))

            {

                WindowSmartPartInfo wspi = new WindowSmartPartInfo();

                wspi.Modal = true;

                wspi.MaximizeBox = false;//去掉最大化

                wspi.MinimizeBox = false;//去掉最小化

                wspi.ControlBox = true;

 

                wspi.Keys[WindowWorkspaceSetting.TitleLabel] = this.label1;

 

                spi = wspi;

            }

            else

            {

                spi = Activator.CreateInstance(smartPartInfoType) as ISmartPartInfo;

            }

            spi.Description = "this is info description";

            spi.Title = "this.is info title";

            return spi;

        }

        #endregion

    }

 

2.        在項目Infrastructure.Library的類WindowWorkspace中的OnApplySmartPartInfo方法增加部分對應的代碼:

        protected override void OnApplySmartPartInfo(Control smartPart, Microsoft.Practices.CompositeUI.WinForms.WindowSmartPartInfo smartPartInfo)

        {

           。。。

                #region add the label to show the smartpartinfo title

                if (spi.Keys.ContainsKey(WindowWorkspaceSetting.TitleLabel))

                {

                    Label lb = (Label)spi.Keys[WindowWorkspaceSetting.TitleLabel];

                    lb.Text = spi.Title;

                }

                #endregion

 

            }

        }

3.       運行後結果如下:

2.7.1

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章