Method TryGetSource
TryGetSource(ICommandContext?, out View?)
Tries to get the source View from a command context.
public static bool TryGetSource(this ICommandContext? context, out View? source)
Parameters
contextICommandContextsourceViewWhen this method returns, contains the source View if the context is not null and the source weak reference target is still alive; otherwise, null.
Returns
- bool
true if the context is not null and the source weak reference target is still alive; otherwise, false.
Remarks
This is a convenience method to simplify accessing the source view from a command context. It combines null-checking the context and retrieving the weak reference target in one call.
Example usage:
if (commandContext.TryGetSource(out View? view))
{
// use view
}