When you define x:Name in Xaml, the relevant variable is defined automatically.
So you can just use it as it was defined. Something like:
// StackLayout btnStack; // no need - it is defined already
var cnt = btnStack.Children.Count; // should be ok
Probably your problem is that in the line: