I have a UWP app in C# in which I have created a user control. There are a couple instances of the user control on the Main Page. What I am wanting to do is set a variable (bool specifically) that is specific/unique to each instance of my user control.
Essentially what I have is 2 user controls with timers. I have a couple of instances of UserControlA
which is a manual start timer. I then have UserControlB
which can be either manual start or auto start when a particular instance of UserControlA
is started. A & B are separate classes.
Apologies if the way I have explained this is confusing, Thanks in advance for any help offered.
The simplest approach would be have properties in UserControls and you set them from the Main Page based on you logic. Something like as following.
public enum StartType
{
Auto = 0,
Manual = 1
}
public class MyUserControlA
{
public TimeStartType
{
{get;set;}
}
}
public class MyUserControlB
{
public TimeStartType
{
{get;set;}
}
}
public class MainPage : Page
{
MyUserControlA controla = new MyUserControlA();
MyUserControlB controlb = new MyUserControlB();
controla.TimeStartType = StartType.Auto;
controlb.TimeStartType = StartType.Manual;
}
The UserControls will have use these properties internally to decide whether to start timer automatically or manual.
The code snippet is for example. Actual class names, data types and other thing may change as per your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.