locked
Static is not supported in a Windows App project

    Question

  • Hi,

    Trying to get TargetPage="NathsarTS.HebrewWritings.Views.HebrewPage" to work:

    <AppBarButton x:Uid="Remove" Icon="Remove" Label="Remove">
    	<Interactivity:Interaction.Behaviors>
    		<Core:EventTriggerBehavior EventName="Click">
    			<Core:NavigateToPageAction TargetPage="NathsarTS.HebrewWritings.Views.HebrewPage" Parameter="IgnoredParameter"/>
    		</Core:EventTriggerBehavior>
    	</Interactivity:Interaction.Behaviors>
    </AppBarButton>

    by using this located in as assembly xmlns:Models="using:NathsarTS.Common.Models":

    public static class ViewNames
    {
    	.
    	..
    	..
    	public const string HebrewPage = "NathsarTS.HebrewWritings.Views.HebrewPage";
    	...
    }

    I tried this TargetPage="Models:ViewNames.HebrewPage", but doesn't past the define name so my page doesn't navigate.  How do I get this to work in WinRT?

    Also tried what I did in WPF with a DependencyProperty, but can't get it to work:

    <AppBarButton x:Uid="Remove" Icon="Remove" Label="Remove" nameDependencyObjects:ViewNamesParameter.ViewParameters="{Binding Source={x:Static Models:ViewNames.TurahStudyUIMainView}}">

    Thanks!...


    Code is like a box of chocolates!...


    • Edited by VcDeveloper Sunday, September 07, 2014 9:09 PM
    Sunday, September 07, 2014 8:33 PM

Answers

  • Ok thanks, I just went an Bind it to a String Property of my ViewModel:

    <Core:NavigateToPageAction TargetPage="{Binding HebrewPage}" Parameter="IgnoredParameter"/>

    Property:

    public string HebrewPage
    {
        get { return NathsarTS.Common.Models.ViewNames.HebrewPage; }
    }
    


    Code is like a box of chocolates!...

    • Marked as answer by VcDeveloper Tuesday, September 09, 2014 1:54 PM
    Tuesday, September 09, 2014 1:54 PM

All replies

  • Hi VcDeveloper,

    A really easy way to navigate to another page is to use following code instead of BehaviorsSDK, see this for more information: Quickstart: Navigating between pages.

    this.Frame.Navigate(typeof(NathsarTS.HebrewWritings.Views.HebrewPage));

    However if you want to use NavigateToPageAction, you may need add namespace before your page name:

           <AppBarButton x:Uid="Remove" Icon="Remove" Label="Remove">
    <Interactivity:Interaction.Behaviors> <Core:EventTriggerBehavior EventName="Click"> <Core:NavigateToPageAction TargetPage="App175.BlankPage1"/> </Core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors> </AppBarButton>

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Monday, September 08, 2014 2:45 AM
    Moderator
  • Thanks James for the reply!...

    The latter is what I want, but I don't want to hard code the Page namespace, because I want it to be global in other areas of the App that will be using that String.  So if I change the Define Name it will reflect globally.

    So I have it Define above and want to past the name HebrewPage which will past the namespace "NathsarTS.Views.HebrewPage".

    So how do I get the TargetPage Property to past the public const string HebrewPage like you would in WPF?  For example in WPF I did this through a DependencyProperty:

    <RibbonButton Label="Main"
    		SmallImageSource="/Natsar.Common;component/Resources/YahuahBtn16x16.png" 
    		LargeImageSource="/Natsar.Common;component/Resources/YahuahBtn32x32.png"
    		ToolTipTitle="Open Writings (Ctrl+M)"
    		ToolTipDescription="Open content for writings."
    		infDependencyObjects:ViewNamesParameter.ViewParameters="{Binding Source={x:Static inf:ViewNames.TurahStudyUIMainView}}"
    		infDependencyObjects:ActiveViewNamesParameter.ActiveViewParameters="{Binding Source={x:Static inf:ViewNames.TurahStudyUIMainView}}"
    		infDependencyObjects:ExecuteMainParameter.ExecuteMainParameters="{Binding Source={x:Static infModels:ExecuteViewType.MainContent}}"
    		Style="{StaticResource RibbonGroupViewCommandParameter}"/>


    The StaticResource is Define like this:

        <Style TargetType="RibbonButton" x:Key="RibbonGroupViewCommandParameter">
            <Setter Property="Command" Value="{Binding DataContext.RibbonGroupViewCommand, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
            <Setter Property="CommandParameter">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource ActiveViewNamesConverter}">
                        <Binding Path="(infDependencyObjects:ViewNamesParameter.ViewParameters)" RelativeSource="{RelativeSource Mode=Self}"/>
                        <Binding Path="(infDependencyObjects:ActiveViewNamesParameter.ActiveViewParameters)" RelativeSource="{RelativeSource Mode=Self}"/>
                        <Binding Path="(infDependencyObjects:ExecuteViewParameter.ExecuteViewParameters)" RelativeSource="{RelativeSource Mode=Self}"/>
                        <Binding Path="(infDependencyObjects:MainViewNamesParameter.MainNamesParameters)" RelativeSource="{RelativeSource Mode=Self}"/>
                        <Binding Path="(infDependencyObjects:ExecuteMainParameter.ExecuteMainParameters)" RelativeSource="{RelativeSource Mode=Self}"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>


    As you can see I'm using a Define Name, but it will past the String.  This will not work:

    <Core:NavigateToPageAction TargetPage="Models:ViewNames.HebrewPage" Parameter="IgnoredParameter"/>

    nor this:

    <Core:NavigateToPageAction TargetPage="{Models:ViewNames.HebrewPage}" Parameter="IgnoredParameter"/>

    not this:

    <Core:NavigateToPageAction TargetPage="{Binding Source={Models:ViewNames.HebrewPage}}" Parameter="IgnoredParameter"/>

    So how do I get this to work?  I thought this might help Type is not supported in a Windows App project, but it didn't.




    Code is like a box of chocolates!...


    • Edited by VcDeveloper Monday, September 08, 2014 10:42 PM
    Monday, September 08, 2014 8:57 PM
  • As we can see from the documentation of TargetPage Property, the acceptable value is a String. If you really need binding, I would suggest you to create a converter to ensure the output value is a String type.

    Furthermore, Windows Store App is not WPF, there are indeed some limitations for Windows Store App and we should not treat it as how we work with WPF.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 09, 2014 6:49 AM
    Moderator
  • Ok thanks, I just went an Bind it to a String Property of my ViewModel:

    <Core:NavigateToPageAction TargetPage="{Binding HebrewPage}" Parameter="IgnoredParameter"/>

    Property:

    public string HebrewPage
    {
        get { return NathsarTS.Common.Models.ViewNames.HebrewPage; }
    }
    


    Code is like a box of chocolates!...

    • Marked as answer by VcDeveloper Tuesday, September 09, 2014 1:54 PM
    Tuesday, September 09, 2014 1:54 PM