NavigationControl - Continued
-
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
-
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
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 betypeof(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
-
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 betypeof(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
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.
-
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 betypeof(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
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 -
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),
newThe problem is you have two instances of the
NavigationPane
for each expander - one that you create through code and add to theContainerItems
property, and one that's declared in XAML. You don't have a binding for theNavigationPaneModel
property in the XAML, so that property doesn't propagate from theContainerItems
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