犯晕了

来源:互联网 发布:冰点还原精灵类似软件 编辑:程序博客网 时间:2024/04/30 15:48

Silverlight里,把经常用的一些控件封装起来

自定义控件代码:

  public class RoadWayCombobox:ComboBoxEx
    {
        public RoadWayCombobox():base()
        {
           if (!DesignerProperties.IsInDesignTool)
           {
               IsolatedStorageSettings WorkfaceSet = IsolatedStorageSettings.ApplicationSettings;


               if (WorkfaceSet.Contains("Workface"))
               {
                   WorkingFace w = WorkfaceSet["Workface"] as WorkingFace;
                   this.ItemsSource = new List<RoadWay>() {
                       new RoadWay(){ ID=0,Name=w.LeftRoadWayName},
                       new RoadWay(){ ID=1,Name=w.RightRoadWayName}
                   };
                   this.DisplayMemberPath = "Name";
                   this.SelectedValuePath = "ID";
                  
               }
           }
        }
    }

前台界面使用的时候,直接拖拽就行。

绑定值的时候要注意:一定要是自定义控件SelectedValuePath 里的值,之前犯晕,使用的是实体赋值,绑定不了。

   <my:CommTypeControl Width="70" Height="22"  SelectedValueProper="{Binding TypeID,Mode=TwoWay}" >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"  />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </my:CommTypeControl>

0 0
原创粉丝点击