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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현