TemplateSelector for UWP NavigationView The Next CEO of Stack OverflowCannot bind Icon property in NavigationView MenuItemTemplateUWP - setting IsEnabled on NavigationViewItemsWPF Binding to TooltipChange GridView cell background with CellTemplateSelectorHow can you programatically retrieve the DataTemplate used for a specific element in the UI hierarchy?WPF Treeview HierarchicalDataTemplate ItemTemplateSelectorGet items from DataTemplate for ArtOfTest controlsUWP Databinding: How to set button command to parent DataContext inside DataTemplateUWP multiple Countdowns with C# and XAMLWinRT ListView UI Virtualization and DataTemplateSelector with a lot of templates (10-15)Pivot UWP with PivotItems with viewsBackground color not being set with binding and converter in UWP app

"Eavesdropping" vs "Listen in on"

Is it possible to make a 9x9 table fit within the default margins?

What difference does it make matching a word with/without a trailing whitespace?

How seriously should I take size and weight limits of hand luggage?

How can a day be of 24 hours?

MT "will strike" & LXX "will watch carefully" (Gen 3:15)?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

logical reads on global temp table, but not on session-level temp table

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

How dangerous is XSS

Why can't we say "I have been having a dog"?

Free fall ellipse or parabola?

Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?

Find the majority element, which appears more than half the time

Is there a rule of thumb for determining the amount one should accept for of a settlement offer?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Why was Sir Cadogan fired?

How to show a landlord what we have in savings?

Why did early computer designers eschew integers?

Variance of Monte Carlo integration with importance sampling

Ising model simulation

Can I cast Thunderwave and be at the center of its bottom face, but not be affected by it?

Compilation of a 2d array and a 1d array

Early programmable calculators with RS-232



TemplateSelector for UWP NavigationView



The Next CEO of Stack OverflowCannot bind Icon property in NavigationView MenuItemTemplateUWP - setting IsEnabled on NavigationViewItemsWPF Binding to TooltipChange GridView cell background with CellTemplateSelectorHow can you programatically retrieve the DataTemplate used for a specific element in the UI hierarchy?WPF Treeview HierarchicalDataTemplate ItemTemplateSelectorGet items from DataTemplate for ArtOfTest controlsUWP Databinding: How to set button command to parent DataContext inside DataTemplateUWP multiple Countdowns with C# and XAMLWinRT ListView UI Virtualization and DataTemplateSelector with a lot of templates (10-15)Pivot UWP with PivotItems with viewsBackground color not being set with binding and converter in UWP app










0















how do I correctly use the MenuItemTemplateSelector for UWP NavigationView?
I have looked up some samples from the internet and tried them (Code below). But it did not work as it should it just prints the class name.
Currently im running on Windows version 1809. I have already tried using the same template in a listView and it works, so I was wondering if there might be bug in NavigationView, or am I missing something?
Thanks in advance :)



This is what my code looks like:



Create template selector:



public class NavigationItemTemplateSelector : DataTemplateSelector

public DataTemplate DriveTemplate get; set;
public DataTemplate PathTemplate get; set;

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)

return SelectTemplateCore(item);


protected override DataTemplate SelectTemplateCore(object item)

if (item is Drive) return DriveTemplate;
if (item is FileSystemElement) return PathTemplate;

return base.SelectTemplateCore(item);




Put something like this in your page resources:



 <Page.Resources>
<DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
<StackPanel>
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
<StackPanel>
<SymbolIcon Symbol="x:Bind Icon" />
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<entities:NavigationItemTemplateSelector x:Key="NVMenuItemsSelector"
DriveTemplate="StaticResource DriveDataTemplate"
PathTemplate="StaticResource FileSystemDataTemplate">
</entities:NavigationItemTemplateSelector>
</Page.Resources>




Tell NavigationView it should use this TemplateSelector



<NavigationView MenuItemsSource="x:Bind ViewModel.NavigationItems, Mode=OneWay" 
MenuItemTemplateSelector="StaticResource NVMenuItemsSelector">


enter image description here










share|improve this question
























  • Please refer this case reply.

    – Nico Zhu - MSFT
    Mar 22 at 9:34















0















how do I correctly use the MenuItemTemplateSelector for UWP NavigationView?
I have looked up some samples from the internet and tried them (Code below). But it did not work as it should it just prints the class name.
Currently im running on Windows version 1809. I have already tried using the same template in a listView and it works, so I was wondering if there might be bug in NavigationView, or am I missing something?
Thanks in advance :)



This is what my code looks like:



Create template selector:



public class NavigationItemTemplateSelector : DataTemplateSelector

public DataTemplate DriveTemplate get; set;
public DataTemplate PathTemplate get; set;

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)

return SelectTemplateCore(item);


protected override DataTemplate SelectTemplateCore(object item)

if (item is Drive) return DriveTemplate;
if (item is FileSystemElement) return PathTemplate;

return base.SelectTemplateCore(item);




Put something like this in your page resources:



 <Page.Resources>
<DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
<StackPanel>
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
<StackPanel>
<SymbolIcon Symbol="x:Bind Icon" />
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<entities:NavigationItemTemplateSelector x:Key="NVMenuItemsSelector"
DriveTemplate="StaticResource DriveDataTemplate"
PathTemplate="StaticResource FileSystemDataTemplate">
</entities:NavigationItemTemplateSelector>
</Page.Resources>




Tell NavigationView it should use this TemplateSelector



<NavigationView MenuItemsSource="x:Bind ViewModel.NavigationItems, Mode=OneWay" 
MenuItemTemplateSelector="StaticResource NVMenuItemsSelector">


enter image description here










share|improve this question
























  • Please refer this case reply.

    – Nico Zhu - MSFT
    Mar 22 at 9:34













0












0








0








how do I correctly use the MenuItemTemplateSelector for UWP NavigationView?
I have looked up some samples from the internet and tried them (Code below). But it did not work as it should it just prints the class name.
Currently im running on Windows version 1809. I have already tried using the same template in a listView and it works, so I was wondering if there might be bug in NavigationView, or am I missing something?
Thanks in advance :)



This is what my code looks like:



Create template selector:



public class NavigationItemTemplateSelector : DataTemplateSelector

public DataTemplate DriveTemplate get; set;
public DataTemplate PathTemplate get; set;

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)

return SelectTemplateCore(item);


protected override DataTemplate SelectTemplateCore(object item)

if (item is Drive) return DriveTemplate;
if (item is FileSystemElement) return PathTemplate;

return base.SelectTemplateCore(item);




Put something like this in your page resources:



 <Page.Resources>
<DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
<StackPanel>
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
<StackPanel>
<SymbolIcon Symbol="x:Bind Icon" />
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<entities:NavigationItemTemplateSelector x:Key="NVMenuItemsSelector"
DriveTemplate="StaticResource DriveDataTemplate"
PathTemplate="StaticResource FileSystemDataTemplate">
</entities:NavigationItemTemplateSelector>
</Page.Resources>




Tell NavigationView it should use this TemplateSelector



<NavigationView MenuItemsSource="x:Bind ViewModel.NavigationItems, Mode=OneWay" 
MenuItemTemplateSelector="StaticResource NVMenuItemsSelector">


enter image description here










share|improve this question
















how do I correctly use the MenuItemTemplateSelector for UWP NavigationView?
I have looked up some samples from the internet and tried them (Code below). But it did not work as it should it just prints the class name.
Currently im running on Windows version 1809. I have already tried using the same template in a listView and it works, so I was wondering if there might be bug in NavigationView, or am I missing something?
Thanks in advance :)



This is what my code looks like:



Create template selector:



public class NavigationItemTemplateSelector : DataTemplateSelector

public DataTemplate DriveTemplate get; set;
public DataTemplate PathTemplate get; set;

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)

return SelectTemplateCore(item);


protected override DataTemplate SelectTemplateCore(object item)

if (item is Drive) return DriveTemplate;
if (item is FileSystemElement) return PathTemplate;

return base.SelectTemplateCore(item);




Put something like this in your page resources:



 <Page.Resources>
<DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
<StackPanel>
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
<StackPanel>
<SymbolIcon Symbol="x:Bind Icon" />
<TextBlock Text="x:Bind Name" />
</StackPanel>
</DataTemplate>
<entities:NavigationItemTemplateSelector x:Key="NVMenuItemsSelector"
DriveTemplate="StaticResource DriveDataTemplate"
PathTemplate="StaticResource FileSystemDataTemplate">
</entities:NavigationItemTemplateSelector>
</Page.Resources>




Tell NavigationView it should use this TemplateSelector



<NavigationView MenuItemsSource="x:Bind ViewModel.NavigationItems, Mode=OneWay" 
MenuItemTemplateSelector="StaticResource NVMenuItemsSelector">


enter image description here







c# xaml uwp windows-10






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 19:58







P. Steininger

















asked Mar 21 at 19:21









P. SteiningerP. Steininger

1166




1166












  • Please refer this case reply.

    – Nico Zhu - MSFT
    Mar 22 at 9:34

















  • Please refer this case reply.

    – Nico Zhu - MSFT
    Mar 22 at 9:34
















Please refer this case reply.

– Nico Zhu - MSFT
Mar 22 at 9:34





Please refer this case reply.

– Nico Zhu - MSFT
Mar 22 at 9:34












2 Answers
2






active

oldest

votes


















0














Check out this link.



Cannot bind Icon property in NavigationView MenuItemTemplate



I believe wrapping your StackPanels in a ContentPresenter will fix your issue.



<DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
<ContentPresenter>
<StackPanel>
<TextBlock Text="x:Bind Name" />
</StackPanel>
</ContentPresenter>
</DataTemplate>
<DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
<ContentPresenter>
<StackPanel>
<SymbolIcon Symbol="x:Bind Icon" />
<TextBlock Text="x:Bind Name" />
</StackPanel>
</ContentPresenter>
</DataTemplate>





share|improve this answer






























    0














    After looking on above links I decided to put an NavigationViewItem inside my Templates



    <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
    <NavigationViewItem Icon="x:Bind SymbolIcon">
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="x:Bind Name" />
    </StackPanel>
    </NavigationViewItem>
    </DataTemplate>


    And it works. Seems like you have to put NavigationViewItem as first child.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287867%2ftemplateselector-for-uwp-navigationview%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Check out this link.



      Cannot bind Icon property in NavigationView MenuItemTemplate



      I believe wrapping your StackPanels in a ContentPresenter will fix your issue.



      <DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
      <ContentPresenter>
      <StackPanel>
      <TextBlock Text="x:Bind Name" />
      </StackPanel>
      </ContentPresenter>
      </DataTemplate>
      <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
      <ContentPresenter>
      <StackPanel>
      <SymbolIcon Symbol="x:Bind Icon" />
      <TextBlock Text="x:Bind Name" />
      </StackPanel>
      </ContentPresenter>
      </DataTemplate>





      share|improve this answer



























        0














        Check out this link.



        Cannot bind Icon property in NavigationView MenuItemTemplate



        I believe wrapping your StackPanels in a ContentPresenter will fix your issue.



        <DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
        <ContentPresenter>
        <StackPanel>
        <TextBlock Text="x:Bind Name" />
        </StackPanel>
        </ContentPresenter>
        </DataTemplate>
        <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
        <ContentPresenter>
        <StackPanel>
        <SymbolIcon Symbol="x:Bind Icon" />
        <TextBlock Text="x:Bind Name" />
        </StackPanel>
        </ContentPresenter>
        </DataTemplate>





        share|improve this answer

























          0












          0








          0







          Check out this link.



          Cannot bind Icon property in NavigationView MenuItemTemplate



          I believe wrapping your StackPanels in a ContentPresenter will fix your issue.



          <DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
          <ContentPresenter>
          <StackPanel>
          <TextBlock Text="x:Bind Name" />
          </StackPanel>
          </ContentPresenter>
          </DataTemplate>
          <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
          <ContentPresenter>
          <StackPanel>
          <SymbolIcon Symbol="x:Bind Icon" />
          <TextBlock Text="x:Bind Name" />
          </StackPanel>
          </ContentPresenter>
          </DataTemplate>





          share|improve this answer













          Check out this link.



          Cannot bind Icon property in NavigationView MenuItemTemplate



          I believe wrapping your StackPanels in a ContentPresenter will fix your issue.



          <DataTemplate x:Key="FileSystemDataTemplate" x:DataType="entities:FileSystemElement">
          <ContentPresenter>
          <StackPanel>
          <TextBlock Text="x:Bind Name" />
          </StackPanel>
          </ContentPresenter>
          </DataTemplate>
          <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
          <ContentPresenter>
          <StackPanel>
          <SymbolIcon Symbol="x:Bind Icon" />
          <TextBlock Text="x:Bind Name" />
          </StackPanel>
          </ContentPresenter>
          </DataTemplate>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 20:53









          Dan BarrettDan Barrett

          341




          341























              0














              After looking on above links I decided to put an NavigationViewItem inside my Templates



              <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
              <NavigationViewItem Icon="x:Bind SymbolIcon">
              <StackPanel Orientation="Horizontal">
              <TextBlock Text="x:Bind Name" />
              </StackPanel>
              </NavigationViewItem>
              </DataTemplate>


              And it works. Seems like you have to put NavigationViewItem as first child.






              share|improve this answer



























                0














                After looking on above links I decided to put an NavigationViewItem inside my Templates



                <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
                <NavigationViewItem Icon="x:Bind SymbolIcon">
                <StackPanel Orientation="Horizontal">
                <TextBlock Text="x:Bind Name" />
                </StackPanel>
                </NavigationViewItem>
                </DataTemplate>


                And it works. Seems like you have to put NavigationViewItem as first child.






                share|improve this answer

























                  0












                  0








                  0







                  After looking on above links I decided to put an NavigationViewItem inside my Templates



                  <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
                  <NavigationViewItem Icon="x:Bind SymbolIcon">
                  <StackPanel Orientation="Horizontal">
                  <TextBlock Text="x:Bind Name" />
                  </StackPanel>
                  </NavigationViewItem>
                  </DataTemplate>


                  And it works. Seems like you have to put NavigationViewItem as first child.






                  share|improve this answer













                  After looking on above links I decided to put an NavigationViewItem inside my Templates



                  <DataTemplate x:Key="DriveDataTemplate" x:DataType="entities:Drive">
                  <NavigationViewItem Icon="x:Bind SymbolIcon">
                  <StackPanel Orientation="Horizontal">
                  <TextBlock Text="x:Bind Name" />
                  </StackPanel>
                  </NavigationViewItem>
                  </DataTemplate>


                  And it works. Seems like you have to put NavigationViewItem as first child.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 10:44









                  P. SteiningerP. Steininger

                  1166




                  1166



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid …


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287867%2ftemplateselector-for-uwp-navigationview%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?