I'm trying to create a timer for my windows store app,
I've been able to update secondes,but not minutes,
minutes gets its value from a combobox
What I'm doing wrong here?
public sealed partial class MainPage : Page
{
int secCount = 0;
DispatcherTimer timerCount = new DispatcherTimer();
TextBlock time = new TextBlock();
int m;
public MainPage()
{
this.InitializeComponent();
timerCount.Interval = new TimeSpan(0, 0, 0, 1, 0);
timerCount.Tick += new EventHandler<object>(timer_tick);
m = Convert.ToInt32(cMinutes.SelectedValue);
}
private void timer_tick(object sender, object e)
{
time.Text = cHours.SelectedItem + ":" + m + ":" + secCount;
timer.Children.Add(time); //timer is the main grid
secCount--;
if(secCount < 0)
{
secCount = 59;
m--;
}
}
First there is an issue in your code, you are adding the TextBlock time to the timer Grid repeatedly, and you should get an exception complaining that the TextBlock is already one of the Grid's children.
The answer to your question
You need to update cMinutes' SelectedValue or SelectedIndex.
Some enhancements:
I move the initialization of the fields timerCount and time into the MainPage's constructor, it is a good practice to initialize all the fields in one place.
Since int (secCount and m) is default to 0, you don't need to set the initial values for ints.
public sealed partial class MainPage : Page
{
int secCount;
int m;
DispatcherTimer timerCount; //declare here, initialize in constructor
TextBlock time; //declare here, initialize in constructor
public MainPage()
{
this.InitializeComponent();
time = new TextBlock();
timer.Children.Add(time); //fix: only add ONCE
//populate the Combobox
cMinutes.Items.Add(0);
cMinutes.Items.Add(1);
cMinutes.Items.Add(2);
cMinutes.SelectedIndex = 2;
m = Convert.ToInt32(cMinutes.SelectedValue);
timerCount = new DispatcherTimer();
timerCount.Interval = new TimeSpan(0, 0, 0, 1, 0);
timerCount.Tick += new EventHandler<object>(timer_tick);
timerCount.Start();
}
private void timer_tick(object sender, object e)
{
time.Text = cHours.SelectedItem + ":" + m + ":" + secCount;
secCount--;
if (secCount < 0)
{
secCount = 59;
m--;
if (cMinutes.Items.Contains(m)) //fix: update Combobox's selected value
cMinutes.SelectedValue = m;
}
}
}
Related
I am trying to change the background of a ListViewItem from an attached property. The following code works until the ListViewItem is scrolled out of the displayed ListView. The error is that the timer fires on a ListViewItem that has been disconnected.
{System.Windows.Controls.ListViewItem:
{DisconnectedItem}} System.Windows.Controls.ListViewItem
How to test for a disconnected item in visual studio 2010?
TIA
namespace Stargate_V
{
// Using singleton pattern to create one time to be shared among all ListViewItem instances.
public static class ListTimer
{
// Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the
// Dispatcher and a DispatcherPriority can be set on the DispatcherTimer. Timer runs in its own thread.
private static readonly Timer listTimer;
static ListTimer()
{
listTimer = new Timer { AutoReset = true, Enabled = true, Interval = 10 * 1000 }; // Interval in milliseconds
listTimer.Elapsed += listTimer_Elapsed;
}
static void listTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (ListTimerEvent != null)
{
ListTimerEvent(sender, e);
}
}
public static event EventHandler ListTimerEvent;
}
// Static classes can not implement an interface. (Hence : INotifyPropertyChanged can not be used).
public static class ListViewItemBehavior
{
// Hint: create this with "propa" then tab
public static string GetMyValue(DependencyObject obj)
{
return (string)obj.GetValue(MyValueProperty);
}
public static void SetMyValue(DependencyObject obj, string value)
{
obj.SetValue(MyValueProperty, value);
}
// Using a DependencyProperty as the backing store for MyValue. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyValueProperty =
DependencyProperty.RegisterAttached("MyValue", typeof(Object), typeof(ListViewItemBehavior), new UIPropertyMetadata(null, OnMyValueChanged));
static void OnMyValueChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
{
var item = depObj as ListViewItem;
if (item == null) return;
// This is unable to pass the instance data: ListTimer.ListTimerEvent +=new EventHandler(ListTimer_ListTimerEvent);
// Use an anonymous method in the OnMyValueChanged to specify the timer event handler. This will give access to the specific
// ListViewItem.
ListTimer.ListTimerEvent += (sender, e) =>
{
Timer timer = sender as Timer;
// The Timer is running on a different thread then the ListViewItem item
item.Dispatcher.Invoke((Action)(() =>
{
--THIS FAILS WHEN ITEM HAS BEEN SCROLLED OUT OF VIEW AND DISCONNECTED ---
View_encountertime vt = item.DataContext as View_encountertime;
item.Background = Brushes.Azure;
// convert checkin time to a datetime.
var b = vt.Checkin;
DateTime z = (DateTime)vt.Tencounter;
// string sdt = DateTime.Now.ToShortDateString() + " " + values[0].ToString();
// DateTime checkin = DateTime.Parse(sdt);
// get current time.
// DateTime now = DateTime.Now;
DateTime now = new DateTime(2015, 2, 13, 11, 30, 5);
TimeSpan ts = now.Subtract(z);
if (ts.CompareTo(WaitingTime.ninetymin) < 1) item.Background = Brushes.Orange; // orange
if (ts.CompareTo(WaitingTime.seventyfivemin) < 1) item.Background = Brushes.Yellow; // yellow
if (ts.CompareTo(WaitingTime.sixtymin) < 1) item.Background = Brushes.Green; // green
if (ts.CompareTo(WaitingTime.fortyfivemin) < 1) item.Background = Brushes.Turquoise; // turquose
if (ts.CompareTo(WaitingTime.thirtymin) < 1) item.Background = Brushes.Blue; // blue
if (ts.CompareTo(WaitingTime.fifteenmin) < 1) item.Background = Brushes.Violet; // violet
}));
};
}
}
// Waiting times
public static class WaitingTime
{
public static TimeSpan fifteenmin;
public static TimeSpan thirtymin;
public static TimeSpan fortyfivemin;
public static TimeSpan sixtymin;
public static TimeSpan seventyfivemin;
public static TimeSpan ninetymin;
static WaitingTime()
{
fifteenmin = new TimeSpan(0, 15, 0);
thirtymin = new TimeSpan(0, 30, 0);
fortyfivemin = new TimeSpan(0, 45, 0);
sixtymin = new TimeSpan(0, 60, 0);
seventyfivemin = new TimeSpan(0, 75, 0);
ninetymin = new TimeSpan(0, 90, 0);
}
} // end class WaitingTime
}
Has nothing to do with the version of Visual Studio. Has to do with the version of .NET. In 4.5 and above, you can use BindingOperations.DisconnectedSource. Before 4.5, .NET did not expose this member, so you have to do a string compare.
I am trying to create a car game using pictureboxes and timers
Here is my code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PictureBox car = new PictureBox();
Timer t = new Timer();
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//Right arrow key
if (e.KeyCode.Equals(Keys.Right) && carPlayer.Location.X < 300)
{
int x = carPlayer.Location.X + 5;
int y = carPlayer.Location.Y;
int width = carPlayer.Size.Width;
int height = carPlayer.Size.Height;
carPlayer.SetBounds(x, y, width, height);
}
//Left arrow key
if (e.KeyCode.Equals(Keys.Left) && carPlayer.Location.X > 35)
{
int x = carPlayer.Location.X - 5;
int y = carPlayer.Location.Y;
int width = carPlayer.Size.Width;
int height = carPlayer.Size.Height;
carPlayer.SetBounds(x, y, width, height);
}
if (e.KeyCode.Equals(Keys.Space))
{
spawnCar();
}
}
void spawnCar()
{
string[] cars = { "data/car_red.png", "data/car_blue.png", "data/car_green.png", "data/car_grey.png" };
Random rand = new Random();
car.SizeMode = PictureBoxSizeMode.StretchImage;
car.Image = Image.FromFile(cars[rand.Next(0, 4)]);
car.Visible = true;
if (rand.Next(0,2) == 0)
{
car.SetBounds(100, 10, 50, 85);
}
else
{
car.SetBounds(250, 10, 50, 85);
}
this.Controls.Add(car);
car.BringToFront();
t.Interval = 1;
t.Tick += new EventHandler(t_Tick);
t.Start();
}
private void t_Tick(object sender, EventArgs e)
{
if (car.Bounds.IntersectsWith(carPlayer.Bounds))
{
t.Stop();
car.Image = Image.FromFile("data/car_wreck.png");
carPlayer.Image = Image.FromFile("data/player_wreck.png");
}
if (car.Bounds.Y > 340)
{
t.Stop();
this.Controls.Remove(car);
}
else
{
car.Top++;
}
}
}
http://i.stack.imgur.com/NhCgY.png
Now when I press space once the car appears at the top and moves down slowly and disappears on reaching the bottom but when I press space multiple time the speed of the car gets faster and faster .
Anyone please help me make the car move at same speed everytime it is created.
Thanks
The problem is that you are registering a new Tick event handler with each car spawn, you only want to do this once. However, there isn't an easy way to check if a handler has been assigned yet so I would recommend using a global flag...
//at class level
bool eventSet = false;
//in spawn method
t.Interval = 1;
if(!eventSet)//check if no handler assigned yet
{
t.Tick += new EventHandler(t_Tick);
eventSet = true;
}
t.Start();
Alternatively, you could attempt to remove the handler before assigning...
//in spawn method
t.Interval = 1;
t.Tick -= new EventHandler(t_Tick);//remove previous one if it exists
t.Tick += new EventHandler(t_Tick);
t.Start();
public void ItemGot()
{
number = number + 1; //Increment by 1
quantity.Text = ("x" + number); //Overwrite Text
quantity.Refresh(); //Updates the text
}
Hello, I have this code above. When this method runs, the text of a label I set up earlier should change the text to the one i set below. However, its not doing it. Furthermore, by setting breakpoints in Visual Studio, I have determined that:
The method is being called,
Number is being incremented properly.
There should be NO reason why this not working, because the program is recognizing that number is increasing by one. My friend said a similar question here. Still no help, and now that code is outdated. Please help!
EDIT: how I added the quantity label
First, I initialized it in the constructor: public Label quantity;
Then I did this: quantity = new Label();
Lastly, in another method, I gave the quantity the following properties:
quantity.Size = new Size(24, 24);
quantity.Text = ("x" + number);
quantity.Left = 48;
Controls.Add(quantity);
number is also in the constructor and is set to 0.
EDIT 2 : I'll Post my whole method
public InventoryScreen()
{
btnItems = new Button();
quantity = new Label();
//call the methods for spawning the buttons
ButtonGenItems(cNumber, btnItems, quantity);
InitializeComponent();
}
public void InventoryScreen_Load(object sender, EventArgs e)
{
}
#region ButtonGenItems Method
public void ButtonGenItems(int cNumber, Button btnItems,Label quantity)
{
int xPos = 126;
int yPos = 25;
for (int n = 0; n < 1; n++)
{
btnItems.Tag = n;
btnItems.Size = new Size(48, 52); //Button size X and Y
btnItems.BackColor = Color.CornflowerBlue;
quantity.Size = new Size(24, 24);
quantity.Text = ("x" + number);
if (yPos > 60) // Five Buttons in one column
{
yPos = 25; //spawn position Y
xPos = xPos + btnItems.Width + 10; //spacing X
}
btnItems.Left = xPos; //Start Button spawn at the Left side
btnItems.Top = yPos; //Start spawn at the top side
quantity.Left = 48;
quantity.Top = 60;
yPos = yPos + btnItems.Height + 10;
btnItems.Text = "Use";
Controls.Add(btnItems); //place Buttons
Controls.Add(quantity);
// the Event of click Button
//btnItems.Click += new System.EventHandler(ItemUse); //to be implimented
}
}
#endregion
public void ItemGot()
{
//*Interestingly, the program recognizes that 'number' is increasing by 1, but label won't update the text
//Furthermore, pressing the actual button will trigger the text update, but simulating a buttonclick WONT DO ANYTHING
Console.WriteLine("Text should now increment by 1"); //Debugging to test method
number = number + 1; //Increment by 1
quantity.Text = ("x" + number); //Overwrite Text
}
}
2.5 This is how the method is being called. This method is located in another class
public void Update(Vector2 pos)
{
this.position = pos; //get char position
Inv = new InventoryScreen(); //create instance of object
charRange = new Rectangle((int)position.X, (int)position.Y, 64, 57); //create rectangle
//Intersection Code, If the character intersects with the item while the item is showing, run below
if (alive && charRange.Intersects(itemRect))
{
alive = false; //stop showing the item
Inv.ItemGot(); //Call the ItemGot class, which adds the item to the inventory screen
}
}
As I understand you have already open/showed form(instance of class InventoryScreen) with your label when you calling Update method, But...
Inside of method Update you creating a new instance of InventoryScreen, and calling function ItemGot with this new instance of form.
I think you need to pass reference of your current instance of InventoryScreen in method Update, then use that reference for calling ItemGot method
public void Update(Vector2 pos, InventoryScreen invscreen)
{
this.position = pos;
charRange = new Rectangle((int)position.X, (int)position.Y, 64, 57);
if (alive && charRange.Intersects(itemRect))
{
alive = false;
invscreen.ItemGot();
}
}
I am creating a UI that will be displaying generated patterns similar to fractals and cellular automation, but they will be continuously generating and automated.
The pixels and pixel colors will be displayed as a grid of squares in a usercontrol. I've already created the usercontrol to display this but since it is constantly calculation at every timer.tick it dramatically slows down the rest of the UI and causes all other elements to stutter.
So I looked into threading and set the "calculating" part in a BackgroundWorker DoWork(), which ultimately didn't end up working out the way I wanted it to. The BackgroundWorker is using data from the main thread (Rectangle[400]), so I had to use Dispatcher.Invoke(new Action(() => { })); which simply defeats the purpose, the program still ran very "stuttery".
So, how can I create a usercontrol...name:display_control entirely on a separate thread and have it appear in another usercontrol...name:unsercontrol1 (Which is running in the main thread), ? Then I could possibly databind the user_input data with the usercontrol1 User_Input_Class instance.
Or, is there a better way to achieve this? Only other way I can think of doing this is to simply create an entirely separate program for the display and share a file containing the user_input data which is very unprofessional.
public partial class Fractal_Gen_A : UserControl
{
byte W_R = 0;
byte W_G = 255;
byte W_B = 0;
int Pixel_Max_Width = 20;
int Pixel_Max_Height = 20;
Color[] Pixel_Color = new Color[20 * 20]; //Width_Max * Canvas_Height_Count
Rectangle[] Pixel = new Rectangle[20 * 20];
Color[] Temp_Color = new Color[20 * 20];
BackgroundWorker worker = new BackgroundWorker();
private void Timer_Tick(object sender, EventArgs e)
{
try { worker.RunWorkerAsync(); }
catch {}
}
Function_Classes.Main_Binder.FGA LB = new Function_Classes.Main_Binder.FGA(); //LB = local Binder
DispatcherTimer Timer = new DispatcherTimer();
public Fractal_Gen_A()
{
LB.Brush = new SolidColorBrush[Pixel_Max_Width * Pixel_Max_Height];
InitializeComponent();
DataContext = LB;
Set_Up_Binded_Brushes();
worker.DoWork += Worker_Work;
Timer.Tick += new EventHandler(Timer_Tick);
Timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
}
private void Set_Up_Binded_Brushes()
{
for (int i = 0; i < Pixel_Max_Width *Pixel_Max_Height; i++)
{
LB.Brush[i] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
private delegate void UpdateMyDelegatedelegate(int i);
private void UpdateMyDelegateLabel(int i){}
private void Worker_Work(object sender, DoWorkEventArgs e)
{
try
{
BackgroundWorker Worker = sender as BackgroundWorker;
SolidColorBrush[] Temp_Brush = new SolidColorBrush[Pixel_Max_Height * Pixel_Max_Width];
for (int h = 0; h < Pixel_Max_Height - 1; h++)
{
for (int w = 0; w < Pixel_Max_Width; w++)
{
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => {
Temp_Brush[((h + 1) * Pixel_Max_Width) + w] = new SolidColorBrush();
Temp_Brush[((h + 1) * Pixel_Max_Width) + w].Color = LB.Brush[(h * Pixel_Max_Width) + w].Color;
}));
}
}
W_R += 23;
for (int w = 0; w < Pixel_Max_Width; w++)
{
W_B += 23 % 255;
W_R += 23 % 255;
Temp_Brush[w].Color = Color.FromRgb(W_R, W_B, W_G);
}
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => {
Array.Copy(Temp_Brush, 0, LB.Brush, 0, Pixel_Max_Height * Pixel_Max_Width);
}));
UpdateMyDelegatedelegate UpdateMyDelegate = new UpdateMyDelegatedelegate(UpdateMyDelegateLabel);
}
catch { }
}
private void Worker_Done(object sender, RunWorkerCompletedEventArgs e)
{
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
double X_Set = Pixel_Canvas.ActualWidth / Pixel_Max_Width;
double Y_Set = Pixel_Canvas.ActualHeight / Pixel_Max_Height;
for (int h = 0; h < Pixel_Max_Height; h++)
{
for (int w = 0; w < Pixel_Max_Width; w++)
{
Pixel_Color[(h * Pixel_Max_Width) + w] = Color.FromRgb(255, 0, 0);
Pixel[(h * Pixel_Max_Width) + w] = new Rectangle();
Pixel[(h * Pixel_Max_Width) + w].Width = Pixel_Canvas.ActualWidth / Pixel_Max_Width;
Pixel[(h * Pixel_Max_Width) + w].Height = Pixel_Canvas.ActualHeight / Pixel_Max_Height;
Pixel[(h * Pixel_Max_Width) + w].Stroke = new SolidColorBrush(Color.FromRgb(100, 100, 100)); //Pixel_Color[(h * Pixel_Max_Width) + w]
Pixel[(h * Pixel_Max_Width) + w].StrokeThickness = .5;
Pixel[(h * Pixel_Max_Width) + w].Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0)); //Pixel_Color[(h * Pixel_Max_Width) + w]
Canvas.SetLeft(Pixel[(h * Pixel_Max_Width) + w], (X_Set * w) + 0);
Canvas.SetTop(Pixel[(h * Pixel_Max_Height) + w], (Y_Set * h) + 0);
Pixel_Canvas.Children.Add(Pixel[(h * Pixel_Max_Height) + w]);
int Temp_Count = (h * Pixel_Max_Width) + w;
string Temp_Bind = "Brush[" + Temp_Count.ToString() + "]";
Binding Bind = new Binding(Temp_Bind);
Pixel[(h * Pixel_Max_Height) + w].SetBinding(Rectangle.FillProperty, Bind );
// Dispatcher.Invoke(new Action(() => { }));
Timer.Start();
}
}
Timer.Start();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window pw = new PopUp_Window();
pw.Show();
}
}
Basically, I am using usercontrols to act as views, 2 will be displayed at all times, one on the left one on the right.
Ok. Delete all your code and start all over.
If you're working with WPF, you really need to embrace The WPF Mentality
This is how you do that in WPF:
<Window x:Class="MiscSamples.Fractals"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Fractals" Height="300" Width="300">
<ItemsControl ItemsSource="{Binding Cells}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="{Binding Size}" Columns="{Binding Size}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" BorderThickness="2">
<Border.Background>
<SolidColorBrush Color="{Binding Color,Mode=OneTime}"/>
</Border.Background>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
Code Behind:
public partial class Fractals : Window
{
public Fractals()
{
InitializeComponent();
DataContext = new FractalViewModel();
}
}
ViewModel:
public class FractalViewModel:PropertyChangedBase
{
private ObservableCollection<FractalCell> _cells;
public int Rows { get; set; }
public int Columns { get; set; }
public ObservableCollection<FractalCell> Cells
{
get { return _cells; }
set
{
_cells = value;
OnPropertyChanged("Cells");
}
}
public FractalViewModel()
{
var ctx = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() => CreateFractalCellsAsync())
.ContinueWith(x => Cells = new ObservableCollection<FractalCell>(x.Result), ctx);
}
private List<FractalCell> CreateFractalCellsAsync()
{
var cells = new List<FractalCell>();
var colors = typeof(Colors).GetProperties().Select(x => (Color)x.GetValue(null, null)).ToList();
var random = new Random();
for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
cells.Add(new FractalCell() { Row = i, Column = j, Color = colors[random.Next(0, colors.Count)] });
}
}
return cells;
}
}
Data Item:
public class FractalCell:PropertyChangedBase
{
public int Row { get; set; }
public int Column { get; set; }
public Color Color { get; set; }
}
PropertyChangedBase class:
public class PropertyChangedBase:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Result:
Notice how I'm not manipulating any UI elements in procedural code. Everything is done with simple, simple Properties and INotifyPropertyChanged. That's how you program in WPF.
I'm using an ItemsControl with a UniformGrid and a simple DataTemplate for the cells.
The example is generating random colors, but you can get this from whatever data source you like. Notice that the data is completely decoupled from the UI and thus it makes it much easier for you to manipulate your own, simple classes rather than the complex and arcane WPF object model.
It also makes it easier for you to implement a multi-threaded scenario because, again, you are not dealing with the UI, but rather with Data. Remember that the UI can only be manipulated in the UI Thread.
WPF Rocks. Just copy and paste my code in a File -> New Project -> WPF Application and see the results for yourself.
Let me know if you need further help.
I am writting some code in a wpf and I have a mouse that performs a click if the cursor stands still for a few seconds..I want to stop clicking if I open a new wpf window that i created...But it seems that dispachers doesn't stop, even if I tried almost everything...Is there any way??
public DispatcherTimer NewDispacher = new DispatcherTimer();
public DispatcherTimer NewDispacher2 = new DispatcherTimer();
public void CreateDispachers()
{
NewDispacher.Tick += new EventHandler(NewDispacher_Tick);
NewDispacher.Interval = new TimeSpan(0, 0, 0, 0, 10);
NewDispacher.Start();
NewDispacher2.Tick += new EventHandler(NewDispacher2_Tick);
NewDispacher2.Interval = new TimeSpan(0, 0, 0, 4);
NewDispacher2.Start();
}
public void NewDispacher_Tick(object sender, EventArgs e)
{
pointcur = GetCursorPosition();
}
public void NewDispacher2_Tick(object sender, EventArgs e)
{
pointdiff = GetCursorPosition();
if(form1opened==true)
{
NewDispacher.Stop();
NewDispacher = null;
NewDispacher2.Stop();
NewDispacher2 = null;
}
else if ((pointdiff.X >= pointcur.X - 5)
&& (pointdiff.X <= pointcur.X + 5)
&& (pointdiff.Y >= pointcur.Y - 5)
&& (pointdiff.Y <= pointdiff.Y + 5))
{
DoMouseClick();
pointcur.X = 0;
}
}
I make the bool Form1opened=true when the new Form is opened, but even if it gets into the if, dispachers doesn't stop...
Thanks in advance..
The fact is, Stop() *emphasized text*does*emphasized text* stop a DispatcherTimer in its tracks. So there must be an explanation elsewhere in your code. Perhaps you are restarting the timer somehow? Check when the code can execute that instantiates/starts the timers, in case it's getting called again unintentionally.