! 0Falco
! 0Falco
Explore posts from servers
CC#
Created by ! 0Falco on 5/10/2024 in #help
How to refer to the mainwindow class from another class.
Creating a WPF app. I have one main class where all the mainwindow controls are operated.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeAPIs();
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeAPIs();
}
I have a different class that's called FilterManager. In this class I want to operate some data on the mainwindow as well. But I'm not sure how, what's a clean way to refer to the mainwindow from this class?
internal class FilterManager
{
// Reference to MainWindow here
}
internal class FilterManager
{
// Reference to MainWindow here
}
5 replies
CC#
Created by ! 0Falco on 5/9/2024 in #help
How to get rid of nullable warning?
No description
15 replies
CC#
Created by ! 0Falco on 4/17/2024 in #help
Practicing OOP in c#, is this logical implementation of an Interface?
c#
public interface IMembershipManager
{
void RegisterMembership(Person person);
void CancelMembership(Person person);
bool CheckMembership(Person person);
}

public class MembershipManager : IMembershipManager
{
public void RegisterMembership(Person person) {
person.Membership = true;
}
public void CancelMembership(Person person) {
person.Membership = false;
}

public bool CheckMembership(Person person) {
return person.Membership;
}
}

public class Person
{
public Person(string firstname, string lastname, bool membership)
{
FirstName = firstname;
LastName = lastname;
Membership = false;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public bool Membership { get; set; }
}

public class Program{
public static void Main()
{
Person person = new Person("John", "John", false);
Console.WriteLine(person.FirstName);
Console.WriteLine(person.LastName);
Console.WriteLine(person.Membership);

IMembershipManager membershipManager = new MembershipManager();
membershipManager.RegisterMembership(person);
Console.WriteLine(person.FirstName);
Console.WriteLine(person.LastName);
Console.WriteLine(person.Membership);
}
}
c#
public interface IMembershipManager
{
void RegisterMembership(Person person);
void CancelMembership(Person person);
bool CheckMembership(Person person);
}

public class MembershipManager : IMembershipManager
{
public void RegisterMembership(Person person) {
person.Membership = true;
}
public void CancelMembership(Person person) {
person.Membership = false;
}

public bool CheckMembership(Person person) {
return person.Membership;
}
}

public class Person
{
public Person(string firstname, string lastname, bool membership)
{
FirstName = firstname;
LastName = lastname;
Membership = false;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public bool Membership { get; set; }
}

public class Program{
public static void Main()
{
Person person = new Person("John", "John", false);
Console.WriteLine(person.FirstName);
Console.WriteLine(person.LastName);
Console.WriteLine(person.Membership);

IMembershipManager membershipManager = new MembershipManager();
membershipManager.RegisterMembership(person);
Console.WriteLine(person.FirstName);
Console.WriteLine(person.LastName);
Console.WriteLine(person.Membership);
}
}
65 replies
CC#
Created by ! 0Falco on 3/28/2024 in #help
MainWindow' does not contain a definition for 'Button_Click'
No description
21 replies
CC#
Created by ! 0Falco on 3/27/2024 in #help
WPF UI appears different in debug
No description
26 replies
CC#
Created by ! 0Falco on 3/25/2024 in #help
How to create a hotkey so the user can stop/pause the program.
I created a WPF app that automates mouse movements. When the program is active the user cannot press the stop button since the mouse is being used. How do I create a hotkey that can be pressed and stop the programming. I searched the internet and I found 2 options, but I don't know which is best 1. Use a side thread for the program and a main thread that listens for any hotkeys. Then the main thread either pauses or kills the side thread. 2. Use Task ? But I'm not sure how that works.
18 replies