public InstrumentSourceRelationWindow(VmInstrument vmInstrument, EditMode editMode, VmInstrumentSourceRelation vmRelation = null)
        {
            InitializeComponent();
            this._EditMode = editMode;
            this._vmInstrument = vmInstrument;
            this._originRelation = vmRelation;

            if (editMode == EditMode.AddNew)
            {
                this._Relation = new InstrumentSourceRelation() { InstrumentId = this._vmInstrument.Id, SwitchTimeout = 60, Priority = 30 };
                this._Relation.IsActive = vmInstrument.SourceRelations.Count == 0;  // Only for UI display(the backend can process normally)
                this._Relation.IsDefault = false;
                this.IsDefaultCheckBox.IsEnabled = false;
            }
            else
            {
                this._Relation = vmRelation.InstrumentSourceRelation.Clone();
                this.SourcesComboBox.IsEnabled = false;
            }
            InstrumentCodeTextBlock.Text = vmInstrument.Code;
            this.BindSourcesComboBox();
            this.DataContext = this._Relation;

            this._HintMessage = new HintMessage(this.HintTextBlock);
            this.Loaded += InstrumentSourceRelationWindow_Loaded;
        }
 private bool FindVmInstrumentSourceRelation(int relationId, out VmInstrumentSourceRelation relation, out VmInstrument instrument)
 {
     relation = null;
     instrument = null;
     foreach (VmInstrument vmInstrument in this._Instruments)
     {
         relation = vmInstrument.SourceRelations.SingleOrDefault(r => r.Id == relationId);
         if (relation != null)
         {
             instrument = vmInstrument;
             break;
         }
     }
     return relation != null;
 }