no way to dynamically change the breadcrumb title in the navigation
Describe the bug
Sometimes we need to dynamically provide page titles, such as modifyXXX, addXXX, XXXinformation, etc。 I hope to obtain these titles through implementing interfaces, which should also dynamically generate the content of the navgationItem, making it more convenient for us。 Each of these navigationItem has an independent Id for each object.
另:dataContext 也应该提供给接口方法,而不是frameworkViewContent.DataContext,因为frameworkViewContent.DataContext应该是viewmodel,viewmodel的初始化应该交给页面。我们有理由相信初始化过程是有一定业务逻辑的,且viewmode与页面的绑定应该交给页面本身,而不是外部。
所以INavigableView这个接口不应该如此简单!!
再另:internal 关键字是个好东西,但是有些工具方法,工具类能否public; private bool TryToNavigateWithoutINavigationViewItem;private bool NavigateInternal( 这些方法能否改为 protecte ,否则,即使我继承了NavigateView也不好处理,毕竟这些方法的上层方法都是 public virtual 。
该死的,NavigationStackOnCollectionChanged也是私有的,我清空事件也麻烦。
To Reproduce
No response
Expected behavior
No response
Screenshots
No response
OS version
No response
.NET version
No response
WPF-UI NuGet version
No response
Additional context
No response
//希望能够被采纳
///
/// <summary>
/// 获取页面标题
/// </summary>
/// <returns></returns>
String GetTitle() { return String.Empty; }
}
//2
public interface INavigableView<out T>: IBaseNavigableView//继承新接口
{
///
//3 private bool NavigateInternal( INavigationViewItem viewItem, object? dataContext = null, bool addToNavigationStack = false, bool isBackwardsNavigated = false ) { if (NavigationStack.Count > 0 && NavigationStack[^1] == viewItem) { return false; }
var pageInstance = GetNavigationItemInstance(viewItem);
//在这里把上下文数据传进去,这里的上下文被我理解成为页面参数
//对像如果是从缓存在取出来,这样会出问题,所以缓存那里不能使用type,而应该使用 NavigationViewItem.id
// by zhouxin
if (pageInstance != null && pageInstance is IBaseNavigableView obj_BaseNavigableView)
{
obj_BaseNavigableView.Init(dataContext);
if (viewItem.Content == default)
{
viewItem.Content = obj_BaseNavigableView.GetTitle();
}
}
/// <summary>
/// 改为 protected virtual 方便万一有用户继承时重载此方法,或者清除此事件 4
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
[DebuggerStepThrough]
protected virtual void NavigationStackOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
//5 private void UpdateContent(object? content, object? dataContext = null) { //这里不用挂DataContext,这里如果挂了会冲掉页面自身的配置,所以这里不合适 by zhouxin //if (dataContext is not null && content is FrameworkElement frameworkViewContent) //{ // frameworkViewContent.DataContext = dataContext; //}
NavigationViewContentPresenter.Navigate(content);
}