Skip to content

Instantly share code, notes, and snippets.

View vermegi's full-sized avatar
🤩

Gitte Vermeiren vermegi

🤩
  • Microsoft
  • België
View GitHub Profile
@vermegi
vermegi / Fire NotifyPropertyChanged
Last active December 30, 2015 16:29
This gist shows the firing of a NotifyPropertyChanged event through a lambda.
public ObservableCollection<SudokuRowViewModel> Rows
{
get
{
return _rows;
}
set
{
_rows = value;
NotifyPropertyChanged(() => Rows);
@vermegi
vermegi / GetMemberName extension method
Created December 8, 2013 09:12
This ViewModel base class shows wrapping the firing of the PropertyChanged event in a method that provides calling through a lambda expression.
public static class ExpressionExtensions
{
public static string GetMemberName<T>(this Expression<Func<T>> input)
{
if (input == null)
return null;
if (input.Body.NodeType != ExpressionType.MemberAccess)
return null;
@vermegi
vermegi / Databindable command property
Created December 8, 2013 09:15
A command property someone can databind to.
private RelayCommand _newGameCommand;
public RelayCommand NewGame
{
get
{
return _newGameCommand ?? (_newGameCommand = new RelayCommand(CreateNewBoardForCurrentLevel));
}
}
@vermegi
vermegi / RelayCommand
Created December 8, 2013 09:19
An implementation of ICommand which gives you the ability to create ICommands more easily.
public class RelayCommand : ICommand
{
private readonly Action _theCommand;
private readonly Func<object, bool> _canExecute;
public RelayCommand(Action theCommand, Func<object, bool> canExecute = null)
{
_theCommand = theCommand;
_canExecute = canExecute;
}
@vermegi
vermegi / RelayCommand with CanExecute
Created December 8, 2013 09:21
This gist shows the usage of a RelayCommand with a second parameter, which indicates wether a certain command can be executed or not.
public RelayCommand Undo
{
get
{
return _undoCommand ?? (_undoCommand = new RelayCommand(UndoAction, o => _remembrall.HasActions));
}
}
<ItemsControl ItemsSource="{Binding Rows}"
Grid.Column="1"
HorizontalAlignment="Center">
...
<Popup HorizontalAlignment="Center"
VerticalAlignment="Center"
VerticalOffset="-150"
HorizontalOffset="-100"
public class MainViewModel
{
private readonly INavigate _navigationService;
private RelayCommand _startNewEasyGameCommand;
private RelayCommand _startNewIntermediateGameCommand;
private RelayCommand _startNewHardGameCommand;
private RelayCommand _showRulesCommand;
public MainViewModel(INavigate navigationService)
{
public interface INavigate
{
void NavigateTo<TViewModel>() where TViewModel : class;
void NavigateTo<TViewModel, TRequest>(TRequest request) where TViewModel : class;
void GoBack();
}
public class WindowsStoreNavigator : INavigate
{
private readonly Frame _frame;
private readonly IKnowWhereYourViewIs _viewLocator;
private readonly ICreateInstances _ioc;
public WindowsStoreNavigator(Frame frame, IKnowWhereYourViewIs viewLocator, ICreateInstances ioc)
{
_frame = frame;
_viewLocator = viewLocator;
public interface IHandle<TRequest>
{
void Handle(TRequest request);
}