Its been another long coding day and im probably over looking something. But i cant figure out what ive missed
C# Code in ViewModel
public String MainWindowText { get; set; }
public DelegateCommand CommandClose { get; set; }
public TitlebarViewModel()
{
MainWindowText = "My Epic Window!";
CommandClose = new DelegateCommand(CloseMain);
}
public void CloseMain(Object Sender)
{
App.Current.MainWindow.Close();
}
public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public DelegateCommand(Action<object> execute)
: this(execute, null)
{
}
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public virtual bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public virtual void Execute(object parameter)
{
_execute(parameter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
#pragma warning disable 67
public event EventHandler CanExecuteChanged;
#pragma warning restore 67
}
Xaml Code:
<Window.DataContext>
<VM:TitlebarViewModel/>
</Window.DataContext>
<Grid>
<DockPanel>
<Image x:Name="Icon" Width="30" Height="30"/>
<Button x:Name="Close" Content="X" Width="25" Height="25" DockPanel.Dock="Right" Margin="2" Command="{Binding CommandClose}"/>
<TextBlock x:Name="TitleBarText" Text="{Binding MainWindowText}" TextAlignment="Center" Margin="7"/>
</DockPanel>
</Grid>
So the MainWindow text box is showing from what i set in the c# constructor so i know the datacontext is working fine. i just cannot figure out why i cannot get the delegated command to fire when clicking on the button.
I know this is probably really stupid. and its something simple but ive been staring at this screen for 50 minutes and im really over looking for the error. especially when i have done this 100 times and its in other controls all over my solution
Thanks guys.