WPF UI Class Structure For My Project | Amit Padhiyar | Saatody
According to me, The below program is the best standard to define WPF custom UI. There is five core methods for making UI.
The Resize() method can call by DispatcherTimer again and again. Which can call children classes Resize() method also.
- Initialize()
- Repaint()
- Resize()
- Event()
- Refresh()
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
namespace Saatody
{
public class MyGrid : Grid
{
#region Core
public void Initialize()
{
try
{
this.Children.Clear();
Repaint();
Resize();
Event();
Refresh();
this.Children.Add(SomethingElse);
SomethingElse.Initialize();
}
catch (Exception e) { }
}
public void Repaint()
{
try
{
}
catch (Exception e) { }
}
public void Resize()
{
try
{
SomethingElse.Resize();
}
catch (Exception e) { }
}
public void Event()
{
try
{
}
catch (Exception e) { }
}
public void Refresh()
{
try
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 0);
timer.IsEnabled = false;
timer.Tick += new EventHandler(delegate (Object sender, EventArgs e)
{
Resize();
});
timer.Start();
}
catch (Exception e) { }
}
#endregion Core
}
}
The System.Windows.Threading.DispatcherTimer is not for all class. It will inside only main class of UI. Event method can have no argument or one or more arguments. The argument objects must me parent class object for MouseMove event or something like other mouse events.The Resize() method can call by DispatcherTimer again and again. Which can call children classes Resize() method also.
Comments
Post a Comment