Share:

MyRowControl.cs | Drag Object To Scroll In WPF C# | Amit Padhiyar | Saatody

MyRowControl.cs

Drag object using MouseLeftButtonDown, MouseLeftButtonUp and MouseMove. When we drag object using mouse and if object's any part is going outside parent panel then the parent panel margin automatically update and try to in that object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace EffectFeatures
{
    public class MyRowControl : Grid
    {
        private static Button AddRow = new Button();
        public void Initialize()
        {
            try
            {
                this.Children.Clear();
                Repaint();
                Resize();
                Event();
                Refresh();
                this.Children.Add(AddRow);
            }
            catch (Exception e) { }
        }
        public void Repaint()
        {
            try
            {

            }
            catch (Exception e) { }
        }
        public void Resize()
        {
            try
            {
                AddRow.Content = "Add Row";
                AddRow.HorizontalAlignment = HorizontalAlignment.Left;
                AddRow.VerticalAlignment = VerticalAlignment.Top;
                AddRow.Margin = new Thickness(0, 0, 0, 0);
                AddRow.Width = 100;
                AddRow.Height = 20;
            }
            catch (Exception e) { }
        }
        public void Event()
        {
            try
            {
                AddRow.Click += (sender, e) => {
                    MyRowTest.REC.AddRow();
                };
            }
            catch (Exception e) { }
        }
        public void Refresh()
        {
            try
            {
                this.LayoutUpdated += (sender, e) => {
                    Resize();
                };
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = new TimeSpan(0, 0, 0, 0, 1);
                timer.IsEnabled = false;
                timer.Tick += (sender, e) => {
                    Resize();
                };
                timer.Start();
            }
            catch (Exception e) { }
        }
    }
}

Comments

Popular posts from this blog

Get Color From Pixel C# WPF | Saatody | Amit Padhiyar

Basic Audio Operations With MP3 And Wave Files Using NAudio C#

Create Drag And Drop Operation Between DevExpress GridControl And Custom WPF UI | Saatody | Amit Padhiyar