HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Optimize WPF application (2 WPF Windows and a huge mess)

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
applicationwpfmesshugeoptimizewindowsand

Problem

Right now i have a WPF application supposed to display some media into a WPF Window, from actions in another WPF Window ( for example : you write text in a textbox, you click on a button, and the text is displayed in a textblock in the second Window ).

It's working even tho it is completely not optimized, and i would like two things : Separate both windows in different projects in my solution (easy), and maque them communicate not just buy instanciating the display in the control Window, but with design patterns etc... (can't find how because of the Antippatern of my code...)

Here are the Xaml :

MainWindow :


    
    
        
            
        
    
    
    
        
            
                
                
                
                
            
        
    
    
        
        
        
        
    
    
    
        
        
        
        
    
    
    
    


Display :

```

















































































Solution

I won't suggest you any miraculous improvements because the code is extremely hard to read this is, currently the worst mess in your code are the meaningless names.

private void PlayVideo(ref MediaElement a, string url)
private void PlayVideoHolo(ref Display x, string a)
string str = openFileDialog.FileName.Remove(..);


a, x or str are terrible.

This is the first thing you really need to fix. You probably cannot read it anymore let alone someone else.

The General Naming Conventions might help you to choose better names if you're not sure about them.

You also use ref quite often - actually everywhere. This isn't necessary because C# already passes reference types by reference. You need ref only if you want to overwrite the original variable and you're not doing this.

XAML is equally readable

x:Name="image1"
x:Name="textBox"
x:Name="wano__listBx"


Finally. You should get rid of the #regions. They don't do any good to readability.

You might want to read: Are #regions an antipattern or code smell?


I would like two things : Separate both windows in different projects in my solution (easy), and maque them communicate not just buy instanciating the display in the control Window, but with design patterns etc

One can hardly tell what is what. You expect wonders.

Code Snippets

private void PlayVideo(ref MediaElement a, string url)
private void PlayVideoHolo(ref Display x, string a)
string str = openFileDialog.FileName.Remove(..);
x:Name="image1"
x:Name="textBox"
x:Name="wano__listBx"

Context

StackExchange Code Review Q#152582, answer score: 6

Revisions (0)

No revisions yet.