Two-way Binding. Avoiding change of CurrentItem and its representation in Breadcrumb.

2 posts, 0 answers
  1. Ilya
    Ilya avatar
    5 posts
    Member since:
    Aug 2013

    Posted 17 Oct 2013 Link to this post

    Hi.

    I have the following code in ViewModel:
       private ITileItemModel _currentItem;
            public ITileItemModel CurrentItem
            {
                get
                {
                    return _currentItem;
                }
                set
                {
                    if (_currentItem == value) return;
                    if (func()) return;
                    _currentItem = value;
                    RaisePropertyChanged(() => CurrentItem);
                }
            }
    For RaisePropertyChanged I have redefinition, so it will work fine.

    The *,xaml is as following:
    <telerik:RadBreadcrumb x:Name="NavigationBreadcrumb"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                   TextModePath="TilePath"
                                   IsTextModeEnabled="False"
                                   HeaderMemberPath="Header"
                                   HierarchicalItemsSource="Children"
                                   HierarchicalMemberPath="Header"
                                   IsHistoryEnabled="False"
                                   Header="{Binding Root}"   
                                   ItemsSource="{Binding Root.Children}"
                                   CurrentItem="{Binding CurrentItem, Mode=TwoWay}"
                                   >
                 </telerik:RadBreadcrumb>

    If  func() returns true I am not changing CurrentItem, but the breadcrumb shows the item I have selected in it. And I have situation with different values in breadcrumb and CurerntItem.

    Could you help me to resolve this issue?

    Best regards,
    Ilya.
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 21 Oct 2013 Link to this post

    Hello Ilya,
    As far as I understand you want to prevent the selection of a specific item, is that right ? There are two ways to do this:
    - you could bind the IsEnabled property of the RadBreadcrumbBarItems to some property in your business object (e.g. CanSelect).
    - you could add some custom login in your viewModels:
    if (func())
    {
        this.Path = this.previousPath;
        return;
    }
    (in MainViewModel)
    public bool IsSelected
    {
        get
        {
            return this.isSelected;
        }
        set
        {
            if (this.isSelected != value)
            {
                if (Func()) return;
               
                this.isSelected = value;
                this.OnPropertyChanged("IsSelected");
            }
        }
    }
    (in your business item)
    I've attached a sample project which shows both approaches so could you please examine it and if you have further questions feel free to ask. (Note: the is isEnabled style setter is commented out by default).

    Regards,
    Zarko
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top