I’m trying to indent items on a WPF navBar. I can do this in XAML using resources and setting the visualstyle to the appropriate style
<dx:DXWindow.Resources>
<Style x:Key="nestedNavBarItemL1" TargetType="ButtonBase">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
<Style x:Key="nestedNavBarItemL2" TargetType="ButtonBase">
<Setter Property="Margin" Value="40,0,0,0"/>
</Style>
</dx:DXWindow.Resources>
.
.
<dxnb:NavBarItem Content="Source Group"
ImageSource="Images/Icons/Group.png"
VisualStyle="{StaticResource nestedNavBarItemL1}"/>
.
.
However, this is fine if the controls are already created but I’m building up the controls through code using something similar to
NavBarGroup group1 = new NavBarGroup();
group1.Header = eventItems[i].name;
group1.Tag = eventItems[i].id;
for (int i = 0; i < nodeCount; i++)
{
NavBarItem item = new NavBarItem();
item.Content = "Home";
item.Tag = "Level" + i;
//item.VisualStyle = ? How do I set VisualStyle="{StaticResource nestedNavBarItemL1}"/>
group1.Items.Add(item);
}
group1.IsExpanded = false;
navBarControl.Groups.Add(group1);
How do I set VisualStyle="{StaticResource nestedNavBarItemL1}" in code?
Thank you,
O
If you already have style defined in resources, you could use
FindResourcemethod to get it and then assign to the relevant property like this (window is where resource defined):If you don’t you can create it as shown in this codeproject article.