patterncsharpMinor
About Window in XAML
Viewed 0 times
windowaboutxaml
Problem
I just redid Rubberduck's About window in XAML:
I do not like my XAML very much. The way I place the
I am satisfied with my VM, but here it is for completeness. If anything can be improved, please bring it to my attention.
```
public class AboutControlViewModel
{
public string Version
{
get
{
var name = Assembly.GetExecutingAssembly().GetName();
return string.Format(RubberduckUI.Rubberduck_AboutBuild, name.Version, name.ProcessorArchitecture);
}
}
private ICommand _uriCommand;
public ICommand UriCommand
{
get
{
if (_uriCommand != null)
{
return _uriCommand;
}
return _uriCommand = new DelegateCommand(uri =>
{
Process.Start(n
I do not like my XAML very much. The way I place the
StackPanel for the white pane over two rows, only to provide a margin to keep the copyright text out of it seems very hackish. Just as bad is the way I put the Hyperlink elements in a textbox (they are not allowed to be placed directly in a StackPanel because it is not a UIElement), with the XAML-drawn logo (courtesy of ThunderFrame) inside. Is there a cleaner way to do either of these?
http://rubberduckvba.com/
XAML Export Plug-In Version 0.2 (PC/64) -->
I am satisfied with my VM, but here it is for completeness. If anything can be improved, please bring it to my attention.
```
public class AboutControlViewModel
{
public string Version
{
get
{
var name = Assembly.GetExecutingAssembly().GetName();
return string.Format(RubberduckUI.Rubberduck_AboutBuild, name.Version, name.ProcessorArchitecture);
}
}
private ICommand _uriCommand;
public ICommand UriCommand
{
get
{
if (_uriCommand != null)
{
return _uriCommand;
}
return _uriCommand = new DelegateCommand(uri =>
{
Process.Start(n
Solution
private ICommand _uriCommand;
public ICommand UriCommand
{
get
{
if (_uriCommand != null)
{
return _uriCommand;
}
return _uriCommand = new DelegateCommand(uri =>
{
Process.Start(new ProcessStartInfo(((Uri)uri).AbsoluteUri));
});
}
}There's no reason the
ICommand can't be readonly. I don't like having a getter performing assignments like this. Is the cost of instantiating a DelegateCommand such that lazy-initializing the field is warranted? I don't think so.This is much cleaner IMO:
private readonly ICommand _uriCommand;
public ICommand UriCommand { get { return _uriCommand; } }And the constructor can do the assignment, like it does with every other
private readonly field out there, ever:_uriCommand = new DelegateCommand(ExecuteUriCommand);This also eliminates the "return the result of an assignment expression", which I've never come across the absolute requirement to do.
And, the rest of Rubberduck commands are implemented with
ExecuteXxxxxCommand/CanExecuteXxxxxCommand full-fledged methods, which makes debugging easier if needed. An inline delegate really only serves to clutter things up and make things harder to work with when problems arise.private void ExecuteUriCommand(object parameter)
{
Process.Start(new ProcessStartInfo(((Uri)parameter).AbsoluteUri));
}Code Snippets
private ICommand _uriCommand;
public ICommand UriCommand
{
get
{
if (_uriCommand != null)
{
return _uriCommand;
}
return _uriCommand = new DelegateCommand(uri =>
{
Process.Start(new ProcessStartInfo(((Uri)uri).AbsoluteUri));
});
}
}private readonly ICommand _uriCommand;
public ICommand UriCommand { get { return _uriCommand; } }_uriCommand = new DelegateCommand(ExecuteUriCommand);private void ExecuteUriCommand(object parameter)
{
Process.Start(new ProcessStartInfo(((Uri)parameter).AbsoluteUri));
}Context
StackExchange Code Review Q#120589, answer score: 3
Revisions (0)
No revisions yet.