IDE: VS Express 2013 for Windows
Project: Universal
IoC: MEF
Target OS: 8.1
Hi,
In testing on my Windows Phone App on my Device the #if WINDOWS_PHONE_APP directive is not working in my ViewModel, I'm injecting my ViewModels into the DataContext of the my Page's like this.
Injection:
In my ViewModel I check again after the Page is Loaded:
I'm assuming its because the ViewModel become apart of the XAMLDataContext? If so, looks like I may have to use a property setting for this?
Project: Universal
IoC: MEF
Target OS: 8.1
Hi,
In testing on my Windows Phone App on my Device the #if WINDOWS_PHONE_APP directive is not working in my ViewModel, I'm injecting my ViewModels into the DataContext of the my Page's like this.
Injection:
[Export(typeof(HubPage))]
public sealed partial class HubPage : VisualStateAwarePage
{
public HubPage()
{
this.InitializeComponent();
Debug.WriteLine("HubPage InitializeComponent");
#if WINDOWS_PHONE_APP
Debug.WriteLine("directive WINDOWS_PHONE_APP is defined...");
#elif WINDOWS_APP
Debug.WriteLine("directive WINDOWS_APP is defined...");
#else
Debug.WriteLine("Error directive WINDOWS_PHONE_APP/WINDOWS_APP not defined...");
#endif
}
[Import]
public NathsarTS.UILogic.Interfaces.IHubPageViewModel ViewModel
{
set
{
this.DataContext = value;
}
get
{
return DataContext as NathsarTS.UILogic.Interfaces.IHubPageViewModel;
}
}
/// <summary>
/// Called when a part's imports have been satisfied and it is safe to use.
/// </summary>
[OnImportsSatisfied]
public void OnImportsSatisfied()
{
// IPartImportsSatisfiedNotification is useful when you want to coordinate doing some work
// with imported parts independent of when the UI is visible.
Debug.WriteLine("HubPage OnImportsSatisfied instantiation");
this.ViewModel.ObserverHubPageLoadedEventArgs =
Observable.FromEventPattern<object, RoutedEventArgs>(this.pageRoot, "Loaded");
this.ViewModel.DisposableHubPageLoadedEvent =
this.ViewModel.ObserverHubPageLoadedEventArgs.Subscribe(evt => this.ViewModel.OnPageRootHubPageLoadedEvent(evt.Sender, evt.EventArgs));
//NathsarTS.UILogic.Interfaces.IObservableService ObservableService = ServiceLocator.Current.GetInstance<NathsarTS.UILogic.Interfaces.IObservableService>();
//this.ViewModel.NavigationHelper = new NathsarTS.Common.Logic.NavigationHelper(this);
//this.ViewModel.NavigationHelper.LoadState += this.ViewModel.NavigationHelperLoadState;
}
}
In my HubPage (above) and App (below) I check to see if the directive is defined: public App()
{
#if WINDOWS_PHONE_APP
Debug.WriteLine("directive WINDOWS_PHONE_APP is defined...");
#elif WINDOWS_APP
Debug.WriteLine("directive WINDOWS_APP is defined...");
#else
Debug.WriteLine("Error directive WINDOWS_PHONE_APP/WINDOWS_APP not defined...");
#endif
this.InitializeComponent();
this.RequestedTheme = ApplicationTheme.Light;
}
Results: directive WINDOWS_PHONE_APP is defined...In my ViewModel I check again after the Page is Loaded:
public async void OnPageRootHubPageLoadedEvent(object sender, RoutedEventArgs args)
{
Debug.WriteLine("OnPageRootHubPageLoadedEvent instantiation");
#if WINDOWS_PHONE_APP
Debug.WriteLine("OnPageRootHubPageLoadedEvent (Phone) instantiation");
var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
this.DefaultDataModel["Groups"] = sampleDataGroups;
#elif WINDOWS_APP
Debug.WriteLine("OnPageRootHubPageLoadedEvent (Windows) instantiation");
var sampleDataGroup = await NathsarTS.Common.DataModel.SampleDataSource.GetGroupAsync("Group-4");
this.DefaultDataModel["Section3Items"] = sampleDataGroup;
#else
Debug.WriteLine("Error directive WINDOWS_PHONE_APP/WINDOWS_APP not defined...");
await Task.FromResult<object>(null);
#endif
}
Results: Error defining Windows/Phone...I'm assuming its because the ViewModel become apart of the XAMLDataContext? If so, looks like I may have to use a property setting for this?