I'm trying to get Caliburn Micro going in my project and I'm having trouble understanding guard methods (Can*
) in the context of properties that aren't bound to the view (forgive me if I'm getting my terminology wrong).
I've adapted Tim Corey's example to add this snippet:
private bool _connected;
public bool Connected
{
get { return _connected; }
set { _connected = value; NotifyOfPropertyChange(() => Connected); }
}
public bool CanSayHello(bool connected)
{
return connected;
}
public void SayHello(bool connected)
{
Console.WriteLine("Hello!");
}
public bool CanClearText(string firstName, string lastName)
{
if (String.IsNullOrWhiteSpace(firstName) && string.IsNullOrWhiteSpace(lastName))
{
Connected = false;
return false;
}
else
{
Connected = true;
return true;
}
}
And the associated xaml is:
<!-- Row 4 -->
<Button x:Name="ClearText" Grid.Row="4" Grid.Column="1">Clear Names</Button>
<Button x:Name="SayHello" Grid.Row="4" Grid.Column="2">Say Hello</Button>
The SayHello
button is never enabled (even though it seems like it should have the same state as CanClearText
). The intent is to use Connected
as an intermediary property; in the application I'm putting together, the idea is that Connected
is actually set by an external Message (from a model--not connected to a view).
This question gets to it a bit, but I'd like to avoid explicitly calling NotifyOfPropertyChange(() => CanSayHello);
and let the Caliburn Micro framework do the work for me. I'm pretty new to this, and I'm sure there's something simple I'm missing--thanks for your help.