add ability to dynamically set module title and visible from components

This commit is contained in:
Shaun Walker
2022-08-12 13:05:48 -04:00
parent 469b436f10
commit 4cae3f02ed
5 changed files with 94 additions and 29 deletions

View File

@ -1,6 +1,8 @@
@using System.ComponentModel
@namespace Oqtane.Themes.Controls
@inherits ContainerBase
@attribute [OqtaneIgnore]
@inject SiteState SiteState
<span class="app-moduletitle">
<a id="@ModuleState.PageModuleId.ToString()">
@ -9,17 +11,39 @@
</span>
@code {
private string title = "";
private string title = "";
protected override void OnParametersSet()
{
if (!string.IsNullOrEmpty(ModuleState.ControlTitle))
{
title = ModuleState.ControlTitle;
}
else
{
title = ModuleState.Title;
}
}
protected override void OnInitialized()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
}
protected override void OnParametersSet()
{
if (!string.IsNullOrEmpty(ModuleState.ControlTitle))
{
title = ModuleState.ControlTitle;
}
else
{
title = ModuleState.Title;
}
}
private void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "ModuleTitle")
{
if (SiteState.Properties.ModuleTitle.PageModuleId == ModuleState.PageModuleId)
{
title = SiteState.Properties.ModuleTitle.Title;
StateHasChanged();
}
}
}
public void Dispose()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
}
}