void UpdateButtons(object sender, EventArgs args)
 {
     timer.Stop();
     ButtonsHelper.RadioButtonUpdate(m_identifyButton);
     ButtonsHelper.RadioButtonUpdate(m_singleModeButton);
     ButtonsHelper.RadioButtonUpdate(m_multipleModeButton);
 }
        DispatcherTimer timer; //this is a hack to be able to update the buttons correctly

        public UIPadsController(wgssSTU.UsbDevices m_usbDevices, Canvas lcanvas, Grid root, StackPanel tbar,
                                CONFIG config, Window w)
        {
            timer = new DispatcherTimer();
            timer.Stop();
            timer.Interval = TimeSpan.FromMilliseconds(30);
            timer.Tick    += UpdateButtons;

            PadPixelHeight = 117;
            PadPixelWidth  = 100;
            canvas         = lcanvas;
            LayoutRoot     = root;
            m_bitmapRes    = new List <BitmapResource>();
            m_padsUI       = new List <UIPadHandle>();
            m_padsControl  = new List <PadHandle>();

            tbar.Height = 60;
            //////////////////////////////////////////////
            m_identifyButton           = new RadioButton();
            m_identifyButton.GroupName = "Identify";
            m_identifyButton.Height    = tbar.Height - 6;

            Image       im  = new Image();
            BitmapImage bmp = new BitmapImage();

            bmp.BeginInit();
            bmp.UriSource = new Uri(@"pictures/move.png", UriKind.Relative);
            //bmp.DecodePixelHeight = (int)(m_identifyButton.Height * 2*DpiInfo.GetDpi());
            bmp.EndInit();

            im.SnapsToDevicePixels = true;
            im.UseLayoutRounding   = true;
            im.Source = bmp;

            m_identifyButton.Content     = im;
            m_identifyButton.MouseEnter += delegate { ButtonsHelper.RadioButtonUpdate(m_identifyButton); };
            m_identifyButton.MouseLeave += delegate { ButtonsHelper.RadioButtonUpdate(m_identifyButton); };

            tbar.Children.Add(m_identifyButton);

            m_identifyButton.Click  += delegate { IdentifyButtonClick(); };
            m_identifyButton.ToolTip = "Position and identify pads";

            ////////////////////////////////////////////////////////////////

            Separator sep = new Separator();

            sep.SetResourceReference(Control.StyleProperty, "VerticalSeparatorStyle");

            tbar.Children.Add(sep);


            /////////////////////////////////////////////
            m_singleModeButton = new RadioButton();
            //m_identifyButton.GroupName = "Selection Mode";
            m_singleModeButton.Height = tbar.Height - 6;


            m_singleModeButton.MouseEnter += delegate
            {
                ButtonsHelper.RadioButtonUpdate(m_singleModeButton);
                ButtonsHelper.RadioButtonUpdate(m_multipleModeButton);
            };
            m_singleModeButton.MouseLeave += delegate
            {
                ButtonsHelper.RadioButtonUpdate(m_singleModeButton);
                ButtonsHelper.RadioButtonUpdate(m_multipleModeButton);
            };

            RadioGifControl gifSingle = new RadioGifControl("pictures/select_singleBIG.gif", m_singleModeButton);

            m_singleModeButton.MouseEnter += delegate { gifSingle.Play(); };
            m_singleModeButton.MouseLeave += delegate { gifSingle.Stop(); };

            tbar.Children.Add(m_singleModeButton);

            m_singleModeButton.ToolTip = "Select single pad";
            m_singleModeButton.Click  += delegate
            {
                ChangeSelectionMode(m_singleModeButton, new EventArgs());
            };


            //////////////////////////////////////////////

            m_multipleModeButton = new RadioButton();
            //m_multipleModeButton.GroupName = "Selection Mode";
            m_multipleModeButton.Height = tbar.Height - 6;

            m_multipleModeButton.MouseEnter += delegate
            {
                ButtonsHelper.RadioButtonUpdate(m_multipleModeButton);
                ButtonsHelper.RadioButtonUpdate(m_singleModeButton);
            };
            m_multipleModeButton.MouseLeave += delegate
            {
                ButtonsHelper.RadioButtonUpdate(m_multipleModeButton);
                ButtonsHelper.RadioButtonUpdate(m_singleModeButton);
            };


            RadioGifControl gifMultiple = new RadioGifControl("pictures/select_multipleBIG.gif", m_multipleModeButton);

            m_multipleModeButton.MouseEnter += delegate { gifMultiple.Play(); };
            m_multipleModeButton.MouseLeave += delegate { gifMultiple.Stop(); };

            tbar.Children.Add(m_multipleModeButton);
            m_multipleModeButton.ToolTip = "Select multiple pads";


            m_multipleModeButton.Click += delegate
            {
                ChangeSelectionMode(m_multipleModeButton, new EventArgs());
            };

            ///////////////////////////////////////////////

            for (int i = 0; i < m_usbDevices.Count; i++)
            {
                m_padsControl.Add(new PadHandle(this, m_usbDevices[i], m_state, i));
            }

            loadBitmaps();

            if (m_usbDevices.Count != 0)
            {
                loadPads(m_usbDevices);
                noOverlappingOnStart();
            }

            m_state = AppState.Selection_Mode;
            m_singleModeButton.IsChecked = true;
            IdentifyButtonClick();
            SetConfig(config);
        }