Exemplo n.º 1
0
        public void AddOscSwiperBtn(ChannelItem ch)
        {
            OscSwiperBtn oscSwiperBtn = new OscSwiperBtn("style_2");

            oscSwiperBtn.Id          = ch.Id;
            oscSwiperBtn.channelItem = ch;
            Binding binding = new Binding {
                Source = ch, Path = new PropertyPath("Color")
            };

            oscSwiperBtn.SetBinding(OscSwiperBtn.colorProperty, binding);
            Binding binding1 = new Binding {
                Source = ch, Path = new PropertyPath("Name")
            };

            oscSwiperBtn.SetBinding(OscSwiperBtn.textProperty, binding1);
            double val = (double)(ruler_y.ActualHeight / 2 - 10 - ch.Offset_Y);

            oscSwiperBtn.SetValue(Canvas.TopProperty, val);
            oscSwiperBtn.SetValue(Canvas.RightProperty, 0d);
            oscSwiperBtn.SetValue(OpacityProperty, 0.7d);

            //订阅事件
            oscSwiperBtn.PreviewMouseDown += SwiperBtn_MouseDown;
            oscSwiperBtn.PreviewMouseMove += SwiperBtn_MouseMove;
            oscSwiperBtn.PreviewMouseUp   += SwiperBtn_MouseUp;

            //添加到canvas中
            this.SwiperCanvas_2.Children.Add(oscSwiperBtn);
        }
Exemplo n.º 2
0
 public void RemoveOscSwiperBtn(int id)
 {
     foreach (UIElement element in SwiperCanvas_2.Children)
     {
         OscSwiperBtn btn = (OscSwiperBtn)element;
         if (btn.Id == id)
         {
             SwiperCanvas_2.Children.Remove(btn);
             return;
         }
     }
 }
Exemplo n.º 3
0
        private void SwiperBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            OscSwiperBtn btn = (OscSwiperBtn)sender;

            isMouseDownSwiperBtn = true;
            if (btn.Style == "style_1")
            {
                start_y = e.GetPosition(SwiperCanvas_1).X;
                first   = (double)btn.GetValue(Canvas.LeftProperty);
            }
            else if (btn.Style == "style_2")
            {
                start_y = e.GetPosition(SwiperCanvas_2).Y;
                first   = (double)btn.GetValue(Canvas.TopProperty);
            }
        }
Exemplo n.º 4
0
        private void SwiperBtn_MouseMove(object sender, MouseEventArgs e)
        {
            OscSwiperBtn btn = (OscSwiperBtn)sender;

            if (isMouseDownSwiperBtn)
            {
                if (btn.Style == "style_1")
                {
                    end_y = e.GetPosition(SwiperCanvas_1).X;
                    double val = first + (end_y - start_y);
                    if (val < -10)
                    {
                        val = -10;
                    }
                    if (val > SwiperCanvas_1.ActualWidth - 20)
                    {
                        val = SwiperCanvas_1.ActualWidth - 20;
                    }
                    btn.SetValue(Canvas.LeftProperty, val);
                    e.Handled = true;
                }
                else if (btn.Style == "style_2")
                {
                    end_y = e.GetPosition(SwiperCanvas_2).Y;
                    double val = first + (end_y - start_y);
                    if (val < -10)
                    {
                        val = -10;
                    }
                    if (val > SwiperCanvas_2.ActualHeight - 20)
                    {
                        val = SwiperCanvas_2.ActualHeight - 20;
                    }
                    btn.channelItem.Offset_Y = ruler_y.ActualHeight / 2 - val - 10;
                    btn.SetValue(Canvas.TopProperty, val);
                    e.Handled = true;
                }
            }
        }