void TranslateCMPosition(MachineUI.ucCM objCM, int position)
        {
            float aspectRatio = 0;

            aspectRatio = Math.Abs(objCM.MinXValue - objCM.MaxXValue) / Math.Abs(objCM.MinValue - objCM.MaxValue);

            TransformGroup     tg = objCM.RenderTransform as TransformGroup;
            TranslateTransform rt = tg.Children[3] as TranslateTransform;

            //   rt.X =  Math.Abs(position - objCM.MinValue) * aspectRatio;
            rt.X = (position - objCM.MinValue) * aspectRatio;
        }
 MachineUI.ucCM GetCMObject(string cmCode)
 {
     MachineUI.ucCM returnCM = null;
     foreach (MachineUI.ucCM objCM in FindVisualChildren <MachineUI.ucCM>(this))
     {
         if (objCM.MachineCode.Equals(cmCode))
         {
             returnCM = objCM;
         }
     }
     return(returnCM);
 }
 void TranslateCM(MachineUI.ucCM objCM)
 {
     //if (objOPCServerDirector == null) objOPCServerDirector = new OPCServerDirector();
     //int pos = 0;
     //if (objOPCServerDirector.IsMachineQualityHealthy(objCM.MachineChannel + "." +
     //    objCM.MachineCode + "." + OpcTags.CM_Position_for_L2) == OPCDA.qualityBits.good)
     //    pos = objOPCServerDirector.ReadTag<Int16>(objCM.MachineChannel + "." + objCM.MachineCode + "." + OpcTags.CM_Position_for_L2);
     //if (pos != 0)
     //{
     //    objCM.Dispatcher.BeginInvoke(new MachineInvokeDelegateCM(TranslateCMPosition), objCM, pos);
     //    //TranslateCMPosition(objCM, pos);
     //}
 }
        //private void UserControl_Initialized()
        //{
        //    garrageGrid.Dispatcher.BeginInvoke(new MachineInvokeDelegate(InitializeCMSettings));
        //    garrageGrid.Dispatcher.BeginInvoke(new MachineInvokeDelegate(InitializeVLCSettings));
        //    garrageGrid.Dispatcher.BeginInvoke(new MachineInvokeDelegate(InitializePSSettings));

        //}
        void InitializeCMSettings()
        {
            try
            {
                foreach (MachineUI.ucCM objCM in FindVisualChildren <MachineUI.ucCM>(this))
                {
                    MachineUI.ucCM objCMClone = objCM;
                    Task.Factory.StartNew(new Action(() => TranslateCM(objCMClone)));

                    objCM.OnPositionChanged += new EventHandler(ucCM_OnPositionChanged);
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
            }
        }
 void SetCMPosition(string cmCode, int position)
 {
     MachineUI.ucCM objCM = GetCMObject(cmCode);
     TranslateCMPosition(objCM, position);
 }