fixed NRE and slightly changed xaml generator