C
C#ā€¢2y ago
Kippachu

ā” Need help with WPF Prism app

Hello, Here is the link to the relevant parts of the code: https://www.onlinegdb.com/DAaTMMPEu2 I am developing a WPF app using Prism. The main view is split into two halves, with two separate modules. On the left side, there is a module displaying a data entry form (which can be switched using the navigation drawer). On the right side, I have created a Preview Text Module that displays a FlowDocument loaded in a PreviewTextService. The idea is that, within my form view models, I load the text I want to display in the PreviewTextService (inside a Dictionary that I convert to a FlowDocument using a converter). Some values are static, while others are linked to property values (properties bound to textboxes inside the form). This way, when I load the form, the default text is displayed in the Preview Text Module. As I input values into the form, the text in the Preview Text Module is automatically updated without regenerating the entire text. Instead, it updates the value linked to the property within the PreviewTextService dictionary. Additionally, by using the dictionary key, I can perform other manipulations. For example, when a user focuses on a textbox, I can signal to the PreviewTextService that this property is focused, and it will automatically change the background to yellow in the preview text RichTextBox. The same behavior applies for validation errors, changing the foreground to red. My problem is that I would like to change the way I am registering properties inside the FormsViewModel. Currently, for every property inside FormsViewModel.Data, I have to register their events in the constructor:
Data.Email.PropertyChanged += (s, e) => OnPreviewContentPropertyChanged($"Data.Email.{e.PropertyName}");
Data.Email.ErrorsChanged += (s, e) => OnPreviewContentErrorChanged($"Data.Email.{e.PropertyName}", e.PropertyName);
Data.Email.PropertyChanged += (s, e) => OnPreviewContentPropertyChanged($"Data.Email.{e.PropertyName}");
Data.Email.ErrorsChanged += (s, e) => OnPreviewContentErrorChanged($"Data.Email.{e.PropertyName}", e.PropertyName);
GDB online Debugger
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
2 Replies
Kippachu
KippachuOPā€¢2y ago
Then, within the OnPreviewContentPropertyChanged method, I have to use a switch statement based on the key value and update the corresponding property in the PreviewTextService dictionary. This means that every time I create a new form implementing Preview Text, I have to manually add all cases inside the switch statement. I am unsure how to replace this code with a more efficient pattern. If anyone could help me improve my code, I would greatly appreciate it! Hello, I didn't get an answer so I'm doing a little up, thanks in advance ! šŸ†™ Thanks in advance !
Accord
Accordā€¢2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server