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
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">
c# xaml uwp windows-10
add a comment |
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">
c# xaml uwp windows-10
Please refer this case reply.
– Nico Zhu - MSFT
Mar 22 at 9:34
add a comment |
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">
c# xaml uwp windows-10
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">
c# xaml uwp windows-10
c# xaml uwp windows-10
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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>
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
add a comment |
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>
add a comment |
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>
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>
answered Mar 21 at 20:53
Dan BarrettDan Barrett
341
341
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 22 at 10:44
P. SteiningerP. Steininger
1166
1166
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Please refer this case reply.
– Nico Zhu - MSFT
Mar 22 at 9:34