wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

no way to dynamically change the breadcrumb title in the navigation

Open zhouxinmail opened this issue 1 year ago • 1 comments

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

zhouxinmail avatar Mar 04 '24 08:03 zhouxinmail

//希望能够被采纳

///

/// 新添加接口1 /// public interface IBaseNavigableView { /// /// 为了兼容以前代码,这里使用默认实现,如果不兼容这里可以不使用默认实现 /// /// void Init(object? dataContext = null) { }

/// <summary>
/// 获取页面标题
/// </summary>
/// <returns></returns>
String GetTitle() { return String.Empty; }

} //2 public interface INavigableView<out T>: IBaseNavigableView//继承新接口 { ///

/// ViewModel used by the view. /// Optionally, it may implement and be navigated by . /// T ViewModel { get; } }

//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);
}

zhouxinmail avatar Mar 04 '24 11:03 zhouxinmail