XE SparkyCracked
XE SparkyCracked
CC#
Created by XE SparkyCracked on 2/7/2025 in #help
How do I "pre-load" a view model
I would like to Preload a WPF ViewModel While Showing a Loading Overlay. I'm working on a WPF application using the MVVM pattern. I have a ViewSelector property that switches between views based on its value. I also have a loading overlay (ViewSelector = 4) that I want to display while a ViewModel is being preloaded. Here’s the problem: One of my views (ViewSelector = 1) takes a long time to initialize because it loads a lot of data and performs heavy processing. I want to: Show the loading overlay (ViewSelector = 4) while this ViewModel is being prepared. Load the heavy ViewModel in the background to keep the UI responsive. Automatically switch to the target view (ViewSelector = 1) when the background preparation is complete. Here’s my current approach in the ViewModel's command:
c#
case "Fitting":
ConfigureFitting();
ViewSelector = 1;
ViewSelector = 4;
await Task.Run(() =>
{
System.Threading.Thread.Sleep(2000);
ViewSelector = 1;
});
break;
c#
case "Fitting":
ConfigureFitting();
ViewSelector = 1;
ViewSelector = 4;
await Task.Run(() =>
{
System.Threading.Thread.Sleep(2000);
ViewSelector = 1;
});
break;
This works but causes an issue because switching to ViewSelector = 1 itself involves heavy operations that block the UI if done synchronously. I’ve considered using BackgroundWorker or other threading mechanisms but ran into problems with updating ViewSelector on the wrong thread.
8 replies
CC#
Created by XE SparkyCracked on 1/22/2025 in #help
Threading issues, settter with ObservableCollection and ListCollectionView
I need assistance in understanding what is happening please. I have an ObservableCollection which I would like to filter according to certain buttons being clicked. (Complete/Busy for example) Now I created a ListCollectionView inside the set to handle the filtering, so the ListCollectionView will be shown on the UI while the ObservableCollection will be used as the data source. The issue with this is the concept that I'd be creating a new ListCollectionView everytime the set is hit (everytime the DisplayList is changed) Here is the snippet of code:
// Constructor
DisplayList = new ObservableCollection<DisplayError>();

// *****
private ObservableCollection<DisplayError> _DisplayList;
private ListCollectionView _DisplayListView;

public ObservableCollection<DisplayError> DisplayList
{
get { return _DisplayList; }
set
{
_DisplayList = value;

_DisplayListView = new ListCollectionView(_DisplayList)
{
Filter = DisplayErrorFilter
};

OnPropertyChanged("DisplayList");
OnPropertyChanged("DisplayListView");
}
}
// Constructor
DisplayList = new ObservableCollection<DisplayError>();

// *****
private ObservableCollection<DisplayError> _DisplayList;
private ListCollectionView _DisplayListView;

public ObservableCollection<DisplayError> DisplayList
{
get { return _DisplayList; }
set
{
_DisplayList = value;

_DisplayListView = new ListCollectionView(_DisplayList)
{
Filter = DisplayErrorFilter
};

OnPropertyChanged("DisplayList");
OnPropertyChanged("DisplayListView");
}
}
Upon trying to initialize my ListCollectionView in the contructor, I ended up with the following code:

// Constructor
DisplayList = new ObservableCollection<DisplayError>();
_DisplayListView = new ListCollectionView(_DisplayList)
{
Filter = DisplayErrorFilter
};


// ******
private ObservableCollection<DisplayError> _DisplayList;
private ListCollectionView _DisplayListView;

public ObservableCollection<DisplayError> DisplayList
{
get { return _DisplayList; }
set
{
_DisplayList = value;
if (_DisplayListView != null)
{
_DisplayListView.Refresh();
}

OnPropertyChanged("DisplayList");
OnPropertyChanged("DisplayListView");
}
}

// Constructor
DisplayList = new ObservableCollection<DisplayError>();
_DisplayListView = new ListCollectionView(_DisplayList)
{
Filter = DisplayErrorFilter
};


// ******
private ObservableCollection<DisplayError> _DisplayList;
private ListCollectionView _DisplayListView;

public ObservableCollection<DisplayError> DisplayList
{
get { return _DisplayList; }
set
{
_DisplayList = value;
if (_DisplayListView != null)
{
_DisplayListView.Refresh();
}

OnPropertyChanged("DisplayList");
OnPropertyChanged("DisplayListView");
}
}
I now get a threading issue upon trying to refresh. I am unsure what is happening.
5 replies
CC#
Created by XE SparkyCracked on 5/13/2024 in #help
✅ UI winforms combobox issue
No description
10 replies
CC#
Created by XE SparkyCracked on 4/5/2024 in #help
✅ Guidance needed for encryption
Good day. I want to dive into creating my own encryption method/class. I want it to be similar to what the big companies do as I want to present it forward to the company I work at. They don't have their own encryption method. I did some research and found the Rijndael algorithm and found it "a worthy" method. My main reason for asking for help is just to ask if you know any recourses or any existing open source methods that I can use to just guide me in completing this project. If you know any other methods that are secure and also really well sourced please let me know. I am doing this project to further my knowledge with C# and actually have an impressive project to showcase if the company decides to not use it.
20 replies
CC#
Created by XE SparkyCracked on 4/3/2024 in #help
✅ BackgroundWorker getting progress
I have a winform applications and with this I have put a ProgressBar on it. I was manually changing the progress inside functions using progressBar.Value = <value> but now that I run my functions in the background using BackgroundWorker, changing that progress is a little harder than I thought. If I am not mistaken the code below is defined as a 'Delegate Invocation' and I use it to run the function I would like to track progress of:
c#
public void ModifyTQWorker(object sender, DoWorkEventArgs e)
{
try
{
object[] args = e.Argument as object[];
if (args != null && args.Length == 4)
{
ClientContext context = args[0] as ClientContext;
Microsoft.SharePoint.Client.List listObj = args[1] as Microsoft.SharePoint.Client.List;
string TQNumber = args[2] as string;
User Raisedby = args[3] as User;

if (context != null && listObj != null && TQNumber != null && Raisedby != null)
{
(sender as BackgroundWorker).ReportProgress(10);
ModifyTQ(context, listObj, TQNumber, Raisedby);
}
else
{
MessageBox.Show("One of the parameters was not given for the ModifyTQWorker.", "Error");
}
}
}catch(Exception ex)
{
MessageBox.Show($"There was an issue modifying the current TQ.\n{ex.Message}", "Error");
}
}
c#
public void ModifyTQWorker(object sender, DoWorkEventArgs e)
{
try
{
object[] args = e.Argument as object[];
if (args != null && args.Length == 4)
{
ClientContext context = args[0] as ClientContext;
Microsoft.SharePoint.Client.List listObj = args[1] as Microsoft.SharePoint.Client.List;
string TQNumber = args[2] as string;
User Raisedby = args[3] as User;

if (context != null && listObj != null && TQNumber != null && Raisedby != null)
{
(sender as BackgroundWorker).ReportProgress(10);
ModifyTQ(context, listObj, TQNumber, Raisedby);
}
else
{
MessageBox.Show("One of the parameters was not given for the ModifyTQWorker.", "Error");
}
}
}catch(Exception ex)
{
MessageBox.Show($"There was an issue modifying the current TQ.\n{ex.Message}", "Error");
}
}
How can I give progress better?
17 replies
CC#
Created by XE SparkyCracked on 3/19/2024 in #help
Casting object to enum class
So I have:
enum AClass { double, int, string }
enum AClass { double, int, string }
And I wanna case my object to that class:
obj a = 0;
(AClass)a;
obj a = 0;
(AClass)a;
There is a reflector to determine what variable type it is but it kinda does this on runtime/compile. I wanna know if there is a way to cast this without wrapping it
114 replies
CC#
Created by XE SparkyCracked on 3/18/2024 in #help
✅ System threading tasks
No description
20 replies
CC#
Created by XE SparkyCracked on 1/28/2024 in #help
✅ Winforms: open two forms at the same time
Good day everyone. So I have an issue (duhh, thats why I am here xD). I am trying to get a screenshot of the users image...I am using two forms to achieve this, one to show the image and another to screenshot. When I try open the first form AspectRatioForm and then the second SelectArea. It throws the issue below:
System.ArgumentException: 'Parameter is not valid.'
System.ArgumentException: 'Parameter is not valid.'
This is the code I wrote:
c#
public void openImageScreenshot(string imageLocationPath, PictureBox pictureBox)
{
SelectArea area = new SelectArea(this);

area.BringToFront();
area.Activate();

using (Image img = Image.FromFile(imageLocationPath))
{
AspectRatioForm aspectRatioForm = new AspectRatioForm(img);
aspectRatioForm.Show();
}
this.Hide();
area.ShowDialog();
// After showing and hiding the SelectArea form, you can access the file path:
string imagePathScreenshot = area.GetScreenshotFilePath();
pictureBox.ImageLocation = imagePathScreenshot;
this.Show();
}
c#
public void openImageScreenshot(string imageLocationPath, PictureBox pictureBox)
{
SelectArea area = new SelectArea(this);

area.BringToFront();
area.Activate();

using (Image img = Image.FromFile(imageLocationPath))
{
AspectRatioForm aspectRatioForm = new AspectRatioForm(img);
aspectRatioForm.Show();
}
this.Hide();
area.ShowDialog();
// After showing and hiding the SelectArea form, you can access the file path:
string imagePathScreenshot = area.GetScreenshotFilePath();
pictureBox.ImageLocation = imagePathScreenshot;
this.Show();
}
Now I don't know why this is happening because if I call them separately in terms of their own functions using ShowDialog they both show one by one (once one form closes the other will show).
7 replies
CC#
Created by XE SparkyCracked on 1/11/2024 in #help
Capturing multiple displays scaling information
No description
31 replies
CC#
Created by XE SparkyCracked on 1/5/2024 in #help
GUI Design / Thoughts on user experience
No description
5 replies
CC#
Created by XE SparkyCracked on 1/2/2024 in #help
Windows Form App - SharePoint Image Upload
Hello everyone, I'm currently working on a Windows Form application using C# and have encountered an issue with uploading images to SharePoint. The objective is to allow users to upload images through the Windows Form, and I want these images to be reflected in a SharePoint table. Here's a quick overview of my process: 1. Users upload images through the Windows Form app. 2. The app uploads images to SharePoint's siteassets. 3. The corresponding SharePoint table gets updated with image information. The challenge I'm facing is that while the images successfully upload to SharePoint's siteassets, they don't appear in the SharePoint table. Bellow is a snippet of code:
while (FileExistsInFolder(context, documentsLibrary, newFileName))
{
fileCount++;
newFileName = $"{coreFileName} ({fileCount}){fileExtension}";
}

// uploading the file
using (FileStream fs = System.IO.File.OpenRead(filePath))
{
FileCreationInformation flciNewFile = new FileCreationInformation();

flciNewFile.ContentStream = fs;
flciNewFile.Url = newFileName;
flciNewFile.Overwrite = false;
Microsoft.SharePoint.Client.File uploadFile = documentsLibrary.Files.Add(flciNewFile);
context.Load(uploadFile);
context.ExecuteQuery();
}
image_url = $"https://<website>.sharepoint.com/{context.Web.ServerRelativeUrl}{siteAssetsUrl}/{newFileName}";
image_url = image_url.Replace(" ", "%20");
Console.WriteLine("Here is the url:\n" + image_url);
MessageBox.Show("This is the url (check console to copy):\n" + image_url);
}
else
{
image_url = string.Empty;
}

//Add new TQ to Register
ListItemCreationInformation newTQInfo = new ListItemCreationInformation();
ListItem newTQ = listObj.AddItem(newTQInfo);
newTQ["RaisedBy"] = Raisedby;
newTQ["Subject_x002f_Description"] = TQSubject.Text;
newTQ["ApplicableDrawing_x002f_ModelNum"] = TQDwgNo.Text;
newTQ["Area_x002f_Equipment"] = TQAreaEquip.Text;
newTQ["ParaMaticSuggestion"] = TQPMRemark.Text;
newTQ["DateRaised"] = dateTimePicker1.Value.ToString();
newTQ["ECRNumber"] = newTQNumber;
newTQ["ContractNumber"] = SelectedProjectItem;

// Attempting to update the attatchement folder
string fileName = "workTester.png";
byte[] fileBytes = System.IO.File.ReadAllBytes(imagePath);
newTQ["OverallImage1"] = fileBytes;
while (FileExistsInFolder(context, documentsLibrary, newFileName))
{
fileCount++;
newFileName = $"{coreFileName} ({fileCount}){fileExtension}";
}

// uploading the file
using (FileStream fs = System.IO.File.OpenRead(filePath))
{
FileCreationInformation flciNewFile = new FileCreationInformation();

flciNewFile.ContentStream = fs;
flciNewFile.Url = newFileName;
flciNewFile.Overwrite = false;
Microsoft.SharePoint.Client.File uploadFile = documentsLibrary.Files.Add(flciNewFile);
context.Load(uploadFile);
context.ExecuteQuery();
}
image_url = $"https://<website>.sharepoint.com/{context.Web.ServerRelativeUrl}{siteAssetsUrl}/{newFileName}";
image_url = image_url.Replace(" ", "%20");
Console.WriteLine("Here is the url:\n" + image_url);
MessageBox.Show("This is the url (check console to copy):\n" + image_url);
}
else
{
image_url = string.Empty;
}

//Add new TQ to Register
ListItemCreationInformation newTQInfo = new ListItemCreationInformation();
ListItem newTQ = listObj.AddItem(newTQInfo);
newTQ["RaisedBy"] = Raisedby;
newTQ["Subject_x002f_Description"] = TQSubject.Text;
newTQ["ApplicableDrawing_x002f_ModelNum"] = TQDwgNo.Text;
newTQ["Area_x002f_Equipment"] = TQAreaEquip.Text;
newTQ["ParaMaticSuggestion"] = TQPMRemark.Text;
newTQ["DateRaised"] = dateTimePicker1.Value.ToString();
newTQ["ECRNumber"] = newTQNumber;
newTQ["ContractNumber"] = SelectedProjectItem;

// Attempting to update the attatchement folder
string fileName = "workTester.png";
byte[] fileBytes = System.IO.File.ReadAllBytes(imagePath);
newTQ["OverallImage1"] = fileBytes;
4 replies