Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. NavigationControl - Continued

NavigationControl - Continued

Scheduled Pinned Locked Moved WPF
comdockercollaborationquestion
5 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I am working on this Navigation control[^]. See this earlier post[^] The code is in this repository[^]. What I'm trying to accomplish now is to have each Pane load individually only when expanded. I added a Func that I want to use inside the pane to call the data

    NavigationPaneInfos = new List
    {
    new NavigationPaneModel
    {
    Header = "Projects",
    NavigationItemType = NavigationItemType.Project,
    IsExpanded = true,
    DataSource = Repository.GetNavigationItems // <=== FUNC
    },

    new NavigationPaneModel
    {
        Header = "Inventory", 
        NavigationItemType = NavigationItemType.Inventory,
        DataSource = Repository.GetNavigationItems
    },
    
    new NavigationPaneModel
    {
        Header = "Companies" , 
        NavigationItemType = NavigationItemType.Company,
        DataSource = Repository.GetNavigationItems
    },
    
    new NavigationPaneModel
    {
        Header = "Employees", 
        NavigationItemType = NavigationItemType.Employee,
        DataSource = Repository.GetNavigationItems
    }
    

    };

    Next I modified the outer container's loading

    private void Load()
    {
    if (NavigationPanes != null)
    {
    ContainerItems = new List();

        foreach (var navigationPaneModel in NavigationPanes)
        {
            var navigationPane = new NavigationPane
            { 
                Header = navigationPaneModel.Header ?? "",
                ItemType = navigationPaneModel.NavigationItemType,
                NavigationPaneModel = navigationPaneModel
                        
            };
            ContainerItems.Add(navigationPane);
    
            navigationPane.IsExpanded = navigationPaneModel.IsExpanded; //<====Triggers loading the pane. Will be set at runtime later
        }
    }
    

    }

    Finally, I changed the pane loading to only happen when IsExpanded is changed:

    public static readonly DependencyProperty

    Richard DeemingR 1 Reply Last reply
    0
    • K Kevin Marois

      I am working on this Navigation control[^]. See this earlier post[^] The code is in this repository[^]. What I'm trying to accomplish now is to have each Pane load individually only when expanded. I added a Func that I want to use inside the pane to call the data

      NavigationPaneInfos = new List
      {
      new NavigationPaneModel
      {
      Header = "Projects",
      NavigationItemType = NavigationItemType.Project,
      IsExpanded = true,
      DataSource = Repository.GetNavigationItems // <=== FUNC
      },

      new NavigationPaneModel
      {
          Header = "Inventory", 
          NavigationItemType = NavigationItemType.Inventory,
          DataSource = Repository.GetNavigationItems
      },
      
      new NavigationPaneModel
      {
          Header = "Companies" , 
          NavigationItemType = NavigationItemType.Company,
          DataSource = Repository.GetNavigationItems
      },
      
      new NavigationPaneModel
      {
          Header = "Employees", 
          NavigationItemType = NavigationItemType.Employee,
          DataSource = Repository.GetNavigationItems
      }
      

      };

      Next I modified the outer container's loading

      private void Load()
      {
      if (NavigationPanes != null)
      {
      ContainerItems = new List();

          foreach (var navigationPaneModel in NavigationPanes)
          {
              var navigationPane = new NavigationPane
              { 
                  Header = navigationPaneModel.Header ?? "",
                  ItemType = navigationPaneModel.NavigationItemType,
                  NavigationPaneModel = navigationPaneModel
                          
              };
              ContainerItems.Add(navigationPane);
      
              navigationPane.IsExpanded = navigationPaneModel.IsExpanded; //<====Triggers loading the pane. Will be set at runtime later
          }
      }
      

      }

      Finally, I changed the pane loading to only happen when IsExpanded is changed:

      public static readonly DependencyProperty

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      That's a nice simple one! :) In NavigationPane.cs you have:

      public static readonly DependencyProperty HeaderProperty =
      DependencyProperty.Register("Header",
      typeof(string),
      typeof(NavigationContainer),
      new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));

      The ownerType needs to be typeof(NavigationPane) instead:

      public static readonly DependencyProperty HeaderProperty =
      DependencyProperty.Register("Header",
      typeof(string),
      typeof(NavigationPane),
      new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      K 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        That's a nice simple one! :) In NavigationPane.cs you have:

        public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header",
        typeof(string),
        typeof(NavigationContainer),
        new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));

        The ownerType needs to be typeof(NavigationPane) instead:

        public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header",
        typeof(string),
        typeof(NavigationPane),
        new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        LOL. I stared at this forever. I need a vacation

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          That's a nice simple one! :) In NavigationPane.cs you have:

          public static readonly DependencyProperty HeaderProperty =
          DependencyProperty.Register("Header",
          typeof(string),
          typeof(NavigationContainer),
          new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));

          The ownerType needs to be typeof(NavigationPane) instead:

          public static readonly DependencyProperty HeaderProperty =
          DependencyProperty.Register("Header",
          typeof(string),
          typeof(NavigationPane),
          new PropertyMetadata("", new PropertyChangedCallback(OnHeaderChanged)));


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          K Offline
          K Offline
          Kevin Marois
          wrote on last edited by
          #4

          OK, so I'm close to done with this, but there's still a related problem. In the MainWindow's code behind I have

          NavigationPaneInfos = new List<NavigationPaneModel>
          {
          new NavigationPaneModel
          {
          Header = "Projects",
          NavigationItemType = NavigationItemType.Project,
          DataSource = Repository.GetNavigationItems,
          IsExpanded = true //<=== THIS TRIGGERS LOAD
          },

          new NavigationPaneModel
          {
              Header = "Inventory", 
              NavigationItemType = NavigationItemType.Inventory,
              DataSource = Repository.GetNavigationItems
          },
          
          new NavigationPaneModel
          {
              Header = "Companies" , 
              NavigationItemType = NavigationItemType.Company,
              DataSource = Repository.GetNavigationItems,
              IsExpanded = true                        //<=== THIS TRIGGERS LOAD
          },
          
          new NavigationPaneModel
          {
              Header = "Employees", 
              NavigationItemType = NavigationItemType.Employee,
              DataSource = Repository.GetNavigationItems
          }
          

          };

          Here's the Pane's NavigationModel DP

          public static readonly DependencyProperty NavigationPaneModelProperty =
          DependencyProperty.Register("NavigationPaneModel",
          typeof(NavigationPaneModel),
          typeof(NavigationPane),
          new PropertyMetadata(null, new PropertyChangedCallback(OnNavigationPaneModelChanged)));

          public NavigationPaneModel NavigationPaneModel
          {
          get { return (NavigationPaneModel)GetValue(NavigationPaneModelProperty); }
          set { SetValue(NavigationPaneModelProperty, value); }
          }
          private static async void OnNavigationPaneModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
          var control = (NavigationPane)d;

          /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
              \* This code checks to see if the Model's IsExpanded is set to True, 
              \* and if it is, sets the IsPaneExpanded DP accordingly, which triggers 
              \* load. below
              \* 
              \* See the IsPaneExpanded DP below
              \* 
              \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
          if (control.NavigationPaneModel.IsExpanded)
          {
              control.IsPaneExpanded = true;
          }
          

          }

          The IsPaneExpanded DP

          public static readonly DependencyProperty IsPaneExpandedProperty =
          DependencyProperty.Register("IsPaneExpanded",
          typeof(bool),
          typeof(NavigationPane),
          new

          Richard DeemingR 1 Reply Last reply
          0
          • K Kevin Marois

            OK, so I'm close to done with this, but there's still a related problem. In the MainWindow's code behind I have

            NavigationPaneInfos = new List<NavigationPaneModel>
            {
            new NavigationPaneModel
            {
            Header = "Projects",
            NavigationItemType = NavigationItemType.Project,
            DataSource = Repository.GetNavigationItems,
            IsExpanded = true //<=== THIS TRIGGERS LOAD
            },

            new NavigationPaneModel
            {
                Header = "Inventory", 
                NavigationItemType = NavigationItemType.Inventory,
                DataSource = Repository.GetNavigationItems
            },
            
            new NavigationPaneModel
            {
                Header = "Companies" , 
                NavigationItemType = NavigationItemType.Company,
                DataSource = Repository.GetNavigationItems,
                IsExpanded = true                        //<=== THIS TRIGGERS LOAD
            },
            
            new NavigationPaneModel
            {
                Header = "Employees", 
                NavigationItemType = NavigationItemType.Employee,
                DataSource = Repository.GetNavigationItems
            }
            

            };

            Here's the Pane's NavigationModel DP

            public static readonly DependencyProperty NavigationPaneModelProperty =
            DependencyProperty.Register("NavigationPaneModel",
            typeof(NavigationPaneModel),
            typeof(NavigationPane),
            new PropertyMetadata(null, new PropertyChangedCallback(OnNavigationPaneModelChanged)));

            public NavigationPaneModel NavigationPaneModel
            {
            get { return (NavigationPaneModel)GetValue(NavigationPaneModelProperty); }
            set { SetValue(NavigationPaneModelProperty, value); }
            }
            private static async void OnNavigationPaneModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
            var control = (NavigationPane)d;

            /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
                \* This code checks to see if the Model's IsExpanded is set to True, 
                \* and if it is, sets the IsPaneExpanded DP accordingly, which triggers 
                \* load. below
                \* 
                \* See the IsPaneExpanded DP below
                \* 
                \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
            if (control.NavigationPaneModel.IsExpanded)
            {
                control.IsPaneExpanded = true;
            }
            

            }

            The IsPaneExpanded DP

            public static readonly DependencyProperty IsPaneExpandedProperty =
            DependencyProperty.Register("IsPaneExpanded",
            typeof(bool),
            typeof(NavigationPane),
            new

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            The problem is you have two instances of the NavigationPane for each expander - one that you create through code and add to the ContainerItems property, and one that's declared in XAML. You don't have a binding for the NavigationPaneModel property in the XAML, so that property doesn't propagate from the ContainerItems instance to the XAML instance. If you add a binding, then the property won't be null:

            Alternatively, remove the ListBox.ItemTemplate so that the list displays the items created in code. You can use a style to set the additional properties:

            		<Setter Property="BorderBrush" Value="Orange" />
            		<Setter Property="BorderThickness" Value="3" />
            		<Setter Property="Background" Value="Red" />
            		<Setter Property="Margin" Value="0,0,0,1" />
            

            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups