Kippachu
Kippachu
CC#
Created by Kippachu on 5/3/2023 in #help
❔ 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);
5 replies
CC#
Created by Kippachu on 4/13/2023 in #help
❔ WPF Date entry Forms MVVM
Hello, I don't understand in WPF when I should use MVVM and when I shouldn't. For example, i'm loading a data entry forms into a region that i've hard coded in XAML :
<UserControl [...]
<Grid Grid.Row="3" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" Style="{StaticResource MaterialDesignOutlinedComboBox}" materialDesign:TextFieldAssist.HasClearButton="True" Margin="8" materialDesign:HintAssist.Hint="Gender" ItemsSource="{Binding Genders}" SelectedItem="{Binding SelectedGender}" />
<TextBox Grid.Column="1" Style="{StaticResource MaterialDesignOutlinedTextBox}" materialDesign:TextFieldAssist.HasClearButton="True" Margin="8" materialDesign:HintAssist.Hint="First Name and Last Name" Text="{Binding FullName}" />
</Grid>

<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Length" Text="{Binding Length}" />
<TextBox Grid.Column="1" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Day" Text="{Binding Day}" />
</Grid>

<TextBox Grid.Row="5" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Work To Do" Text="{Binding WorkToDo}" />
</Grid>

</UserControl>
<UserControl [...]
<Grid Grid.Row="3" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" Style="{StaticResource MaterialDesignOutlinedComboBox}" materialDesign:TextFieldAssist.HasClearButton="True" Margin="8" materialDesign:HintAssist.Hint="Gender" ItemsSource="{Binding Genders}" SelectedItem="{Binding SelectedGender}" />
<TextBox Grid.Column="1" Style="{StaticResource MaterialDesignOutlinedTextBox}" materialDesign:TextFieldAssist.HasClearButton="True" Margin="8" materialDesign:HintAssist.Hint="First Name and Last Name" Text="{Binding FullName}" />
</Grid>

<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Length" Text="{Binding Length}" />
<TextBox Grid.Column="1" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Day" Text="{Binding Day}" />
</Grid>

<TextBox Grid.Row="5" materialDesign:TextFieldAssist.HasClearButton="True" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="8" materialDesign:HintAssist.Hint="Work To Do" Text="{Binding WorkToDo}" />
</Grid>

</UserControl>
Would it be better to use an ItemsControl and define the elements in ViewModel ? Thanks in advance
2 replies
CC#
Created by Kippachu on 4/7/2023 in #help
❔ WPF Framework and components
Hello, my question is simple, if you had to make an app in C# with WPF for your job with a navigation drawer, that is easy to maintain alone, what framework and components would you use ? Let me explain, I've made a start using Syncfusion, it gives me a Spreadsheet viewer control (I must have a Spreadsheet viewer control) but I find it kinda slow, for example when you click on the hamburger button of the navigation drawer it's kinda laggy... For the framework i'm using Prism WPF, but do you know better frameworks ? Thanks in advance for your answers ^^
2 replies
CC#
Created by Kippachu on 10/31/2022 in #help
WPF Find Action IDialogResult using it's string name (Reflection)
5 replies
CC#
Created by Kippachu on 10/19/2022 in #help
Making concrete object classes
private void Initialize_NavigationItems()
{
var fooNavigationItem = new NavigationItem
{
Header = "Foo",
Items = new NavigationItemsCollection
{
new()
{
Header = "Foo task 1",
Command = CommandOpenDialog
}
}
};

NavigationItems = new NavigationItemsCollection
{
fooNavigationItem
};
}
private void Initialize_NavigationItems()
{
var fooNavigationItem = new NavigationItem
{
Header = "Foo",
Items = new NavigationItemsCollection
{
new()
{
Header = "Foo task 1",
Command = CommandOpenDialog
}
}
};

NavigationItems = new NavigationItemsCollection
{
fooNavigationItem
};
}
Hello, in this example is how I create my navigation items but my question is, instead of having too much logic in my method, isn't simply better if I create a FooNavigationItem and move the logic in it ? The method would become =>
private void Initialize_NavigationItems()
{
NavigationItems = new NavigationItemsCollection
{
new FooNavigationItem()
};
}
private void Initialize_NavigationItems()
{
NavigationItems = new NavigationItemsCollection
{
new FooNavigationItem()
};
}
Thanks
4 replies