Version: 2.0 |

ResponsiveNavigation

in namespace DotVVM.Framework.Controls.Bootstrap4

Renders Bootstrap Navbar widget.

Properties

Name Type Description Notes Default Value
ClickBinding ICommandBinding Gets or sets a binding which defines a click action for button items.
attribute
inner element
static value
bindable
default
CollapseButtonTemplate ITemplate Gets or sets the template items for collapse button.
attribute
inner element
static value
bindable
default
DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
HeaderImageUrl String Gets or sets image url that will be put in header. If HeaderText is set it will be used as alternate image text.
attribute
inner element
static value
bindable
default
HeaderLinkUrl String Gets or sets url which will be Header linked to.
attribute
inner element
static value
bindable
default
HeaderText String Gets or sets text that will be put in header. If HeaderImage is set this text will be used as alternate image text.
attribute
inner element
static value
bindable
default
IsEnabledBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is disabled or not.
attribute
inner element
static value
bindable
default
IsSelectedBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is selected or not.
attribute
inner element
static value
bindable
default
ItemsContentTemplate ITemplate Gets or sets the template for contents of the generated items when using the DataSource property.
attribute
inner element
static value
bindable
default
LeftAlignedItems List<IResponsiveNavigationItem> Gets or sets a collection of responsive navigation items which would be aligned to the left.
attribute
inner element
static value
bindable
default
MaximumScreenSizeBeforeCollapse ResponsiveNavigationBreakpoins Gets or sets the maximum screen size in which the navbar should still be collapsed.
attribute
inner element
static value
bindable
default
Medium
NavigateUrlBinding IValueBinding Gets or sets the value binding that points to a property which will be navigated to when the item is clicked.
attribute
inner element
static value
bindable
default
RightAlignedItems List<IResponsiveNavigationItem> Gets or sets a collection of responsive navigation items which would be aligned to the right.
attribute
inner element
static value
bindable
default
ScrollBehavior ResponsiveNavigationScrollBehavior Gets or sets how would ResponsiveNavigation react when It's scrolled out of screen.
attribute
inner element
static value
bindable
default
None
ScrollSpyEnabled Boolean
attribute
inner element
static value
bindable
default
False
ScrollSpyOffset Int32
attribute
inner element
static value
bindable
default
10
TextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the text of the item.
attribute
inner element
static value
bindable
default
Theme ResponsiveNavigationTheme Gets or sets color theme of the navbar. Use ColorDecorators to set text and background colors.
attribute
inner element
static value
bindable
default
Light

Events

Name Type Description

Usage & Scenarios

Renders a Bootstrap Navbar widget.

Each menu item in the ResponsiveNavigation control is represented by the NavigationItem control. You can also use Form and DropDownButton controls inside the navigation bar.

https://getbootstrap.com/docs/4.1/components/navbar/

HTML Rendered by the Control

Sample 1: Basic Usage

The HeaderText property specifies the text that will be placed in the logo section of the navbar.

If the HeaderLinkUrl property is set, the header will be rendered as a hyperlink for that URL.

<bs:ResponsiveNavigation HeaderText="Header" 
                         HeaderLinkUrl="http://www.dotvvm.com">
  <bs:NavigationItem NavigateUrl="https://www.google.com/" 
                     Text="Google"
                     IsSelected="true" />
  <bs:NavigationItem NavigateUrl="http://www.w3schools.com/html/"
                     Text="W3 Schools"
                     Enabled="false" />
</bs:ResponsiveNavigation>

Sample 2: Styling ResponsiveNavigation

If the HeaderImageUrl is set, the header section will render the image and the value of the HeaderText property will be used for the alternate text of the image.

The Theme property allows to switch between Light and Dark theme.

The ScrollBehavior property allows the specify how the navbar should behave when the page is scrolled - the options are None, FixedTop, FixedBottom or StickyTop.

<bs:ResponsiveNavigation 
        HeaderImageUrl="~/Images/person.png" 
        HeaderText="Alt text for image" 
        HeaderLinkUrl="http://www.dotvvm.com" 
        Theme="Dark" 
        ScrollBehavior="StickyTop">

    <bs:NavigationItem NavigateUrl="https://www.google.com/" Text="Google" />
    <bs:NavigationItem NavigateUrl="http://www.w3schools.com/html/" Text="W3 Schools" />
</bs:ResponsiveNavigation>

Sample 3: Alignment

The items inside the ResponsiveNavigation can also be aligned to the left or right side by placing the items into the LeftAlignedItemsTemplate and RightAlignedItemsTemplate properties.

<bs:ResponsiveNavigation HeaderText="Fixed to top">  
  <LeftAlignedItemsTemplate>
    <bs:NavigationItem NavigateUrl="http://www.w3schools.com/html/" Text="W3 Schools" />
  </LeftAlignedItemsTemplate>
  <RightAlignedItemsTemplate>
    <bs:NavigationItem NavigateUrl="https://www.google.com/" Text="Google" />
  </RightAlignedItemsTemplate>
</bs:ResponsiveNavigation>

Sample 4: DropDownButton and Form Controls in ResponsiveNavigation

Except of the NavigationItem controls, you can also use Form and DropDownButton controls inside the navigation bar.

You have to place them in the LeftAlignedItemsTemplate or RightAlignedItemsTemplate elements.

There are some limitations of the Bootstrap navbar. For example, the Form control Type must be set to Inline mode.

<bs:ResponsiveNavigation>
  <LeftAlignedItemsTemplate>
    <bs:NavigationItem NavigateUrl="https://www.google.com/" Text="Google" IsSelected="true" />
    <bs:NavigationItem NavigateUrl="http://www.w3schools.com/html/" Text="W3 Schools" IsDisabled="true" />
    
    <bs:DropDownButton Text="DropDownButton">
      <Items>
        <bs:DropDownButtonItem NavigateUrl="https://www.google.com/">
          Google
        </bs:DropDownButtonItem>
        <bs:DropDownButtonItem NavigateUrl="https://github.com/riganti/dotvvm">
          DotVVM
        </bs:DropDownButtonItem>
      </Items>
    </bs:DropDownButton>
  </LeftAlignedItemsTemplate>

  <RightAlignedItemsTemplate>
    <bs:Form Type="Inline">
      <bs:FormGroup>
        <dot:TextBox Text="TEST" />
      </bs:FormGroup>
    </bs:Form>
  </RightAlignedItemsTemplate>
</bs:ResponsiveNavigation>

Sample 5: Responsiveness

It's possible to collapse the ResponsiveNavigation into a single button when the content cannot fit the screen.

The MaximumScreenSizeBeforeCollapse specifies the maximum screen size in which the navbar should be collapsed. Default is Medium.

Optionally, you can set your own content of the collapsed button by placing in into the CollapsedButtonTemplate template. If the CollapsedButtonTemplate is not set, the standard button with three stripes will be rendered.

<bs:ResponsiveNavigation 
    HeaderText="If this menu cannot fit screen it will collapse to button." 
    MaximumScreenSizeBeforeCollapse="Small">
  <CollapseButtonTemplate>
    <bs:GlyphIcon Icon="Arrow_down" />
  </CollapseButtonTemplate>
  
  <bs:NavigationItem NavigateUrl="https://www.google.cz/" Text="Google" />
  <bs:NavigationItem NavigateUrl="http://www.w3schools.com/html/" Text="W3 Schools" />
</bs:ResponsiveNavigation>

Sample 6: ResponsiveNavigation Data-Binding

The ResponsiveNavigation can be also used with the DataSource property to generate the menu items from the collection.

The TextBinding property specifies which property of the collection items will be used as the text of the menu item.

The NavigateUrlBinding property specifies which property will be used as the URL of the hyperlink.

You can also use the IsEnabledBinding to specify which property controls whether the menu item is enabled or disabled.

Also, there is the IsSelectedBinding property which controls whether the menu item is active.

<bs:ResponsiveNavigation DataSource="{value: LinksDataSet}" 
                         IsEnabledBinding="{value: IsDisabled}" 
						 IsSelectedBinding="{value: IsSelected}"
					     TextBinding="{value: Text}" 
						 NavigateUrlBinding="{value: NavigateUrl}">
</bs:ResponsiveNavigation>
using System.Collections.Generic;
using System.Linq;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ResponsiveNavigation.sample6
{
    public class ViewModel
    {
        public List<NavigationItem> LinksDataSet { get; set; }

        private static IQueryable<NavigationItem> GetData()
        {
            return new[]
            {
                new NavigationItem() {  IsDisabled = false, IsSelected = false, NavigateUrl = "https://www.google.com/", Text = "Google"},
                new NavigationItem() {  IsDisabled = true, IsSelected = false, NavigateUrl = "http://www.w3schools.com/html/", Text = "W3Schools"},
                new NavigationItem() {  IsDisabled = false, IsSelected = true, NavigateUrl = "https://www.microsoft.com/en-us/", Text = "Microsoft"},
                new NavigationItem() {  IsDisabled = false, IsSelected = false, NavigateUrl = "https://github.com/riganti/dotvvm", Text = "DotVVM Github"}
            }.AsQueryable();
        }

        public ViewModel()
        {
            LinksDataSet = new List<NavigationItem>();
            foreach (NavigationItem l in GetData())
            {
                LinksDataSet.Add(l);
            }
        }
    }

    public class NavigationItem
    {
        public string Text { get; set; }
        public string NavigateUrl { get; set; }
        public bool IsSelected { get; set; }
        public bool IsDisabled { get; set; }
    }
}

Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message