This is a migrated thread and some comments may be shown as answers.

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

1 Answer 46 Views
BreadCrumb
This is a migrated thread and some comments may be shown as answers.
Ilya
Top achievements
Rank 1
Ilya asked on 17 Oct 2013, 06:25 AM
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.

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 21 Oct 2013, 09:20 AM
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 >>
Tags
BreadCrumb
Asked by
Ilya
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or