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

Resx Translation Helper, V.2.0

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

Problem

Related to Resx Translation Helper, V.2.0 Remove Files Window

First, I implemented the changes suggested in my last question, then I changed my entire code base to support editing 1-N Resx files. So, this question covers the main window. In particular, I wasn't able to remove all the code from the code-behind, and I have not been able to find a way to do so.

IResxTranslationHelperWindow.cs:

public interface IResxTranslationHelperWindow
{
    object DataContext { set; }
    event EventHandler EndCellEdit;

    void Show();
}


ResxTranslationHelper.xaml:


    
        
    
    
        
        
    
    
        
            
            
        
        
        
    
    
        
            
        
        
            
                
                    
                        
                    
                    
                        
                            
                                
                            
                        
                    
                    
                        
                    
                
            
        
        
            
        
    


ResxTranslationHelper.xaml.cs:

```
private void GridDisplay_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Commit)
{
OnEndCellEdit(e);
}
}

public event EventHandler EndCellEdit;
protected virtual void OnEndCellEdit(DataGridCellEditEndingEventArgs e)
{
var handler = EndCellEdit;
if (handler != null)
{
handler(this, e);
}
}

private void RemoveColumns(DataGrid grid, int columnCount)
{
while (grid.Columns.Count > columnCount) // leave Keys column
{
grid.Columns.RemoveAt(columnCount);
}
}

private void GridDisplay_SourceUpdated(object sender, DataTransferEventArgs e)
{
var grid = (DataGrid) sender;
var source = (ObservableCollection) grid.ItemsSource;

if (source.Count == 0 || source.Fir

Solution

object DataContext { set; }


Set-only properties smell. Give it a getter, it's begging for one. And the implementation has one already anyway.


In particular, I wasn't able to remove all the code from the code-behind, and I have not been able to find a way to do so.

Sure, wpf is great and doing everything in xaml is awesome. But this is also c#, and your code-behind is pretty much only concerned about the presentation of the grid - I see nothing wrong with doing that in the code-behind. That grid isn't exactly trivial, and xaml is verbose by definition - well-written and documented plain code is a better way to do it IMO.

"Zero code-behind" is certainly achievable, only.. for simpler UI's, where data bindings do all the work. The idea behind that isn't that code-behind is evil - it's that the view should only be concerned with presentation; so long as you're not implementing view model logic in the code-behind, plain C# presentation code is perfectly fine.

Code Snippets

object DataContext { set; }

Context

StackExchange Code Review Q#94679, answer score: 2

Revisions (0)

No revisions yet.