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

MVVM Binding

15 Answers 239 Views
BreadCrumb
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 2
Ryan asked on 23 Sep 2011, 07:12 AM
I'm trying to use the Breadcrumb control like cascading drop downs. I can get the navigation through the hierarchy working. My problem is through MVVM I can't figure what property to bind the CurrentItem too, to be accessible in the ViewModel. Also if there is a property that i can bind to can on use the validations options that are built-in to Silverlight 4.

15 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 28 Sep 2011, 01:41 PM
Hi Ryan,

Unfortunately at the moment you cannot bind to the CurrentItem property as it is read-only and you can use it to get the current item but not to set it. However, there is  PITS item associated with this issue and you can vote for it here thus increasing its priority.

Also, the Breadcrumb control doesn't implement a built-in validation mechanism but you can implement your custom logic to control the data validation in the RadBreadcrumb.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ryan
Top achievements
Rank 2
answered on 28 Sep 2011, 04:47 PM
Do you by chance have an example of adding the validation? I'm still relatively new to Silverlight.

The main reason I'm trying to use the Breadcrumb control is because I have a list that has over 30,000 records. The list of records has 4 fields that can be used for grouping as if the records were hierarchical. I didn't want to have for separate controls to get one value. Let me know if there is a better solution for my problem.
0
Tina Stancheva
Telerik team
answered on 28 Sep 2011, 04:50 PM
Hello Ryan,

We don't have any validation examples but if you can elaborate on the validation you would like to implement, we'd gladly help you with a sample solution.

Also, have you checked the RadTreeView control - it also will allow you to display your data in a hierarchical format. You can find its demo here.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ryan
Top achievements
Rank 2
answered on 28 Sep 2011, 05:03 PM
I was looking into the RadTreeView in a ComboBox option, though there was somethings I wanted and I didn't know how to get implemented. For instance I wanted the TreeView to display with a Clear button option above it in the ComboBox. The BreadCrumb doesn't have a clear option either but its easy enough to go back in the hierarchy from any selection.

I was just trying to use the built-in validation around IDataErrorInfo to require a selection in the Breadcrumb.

If I can't get the breadcrumb to function the way I need too, I was going to attempt the below solution.
http://blogs.telerik.com/valerihristov/posts/10-05-12/treeview_in_combobox_with_radcontrols_for_silverlight_or_wpf_final_take.aspx
0
Tina Stancheva
Telerik team
answered on 03 Oct 2011, 03:22 PM
Hi Ryan,

The RadTreeView control also doesn't implement a built-in validation logic. And based on your description, it seems that the RadBreadcrumb control is better suited for your scenario. However, the control always have a selected-current item. Its root item is set by its Header property and if the property isn't set, then the control creates a default root item. This is why your requirement is confusing for me - "use the built-in validation around IDataErrorInfo to require a selection in the Breadcrumb. Can you please describe a scenario where you need such validation? That will help us better understand your case and try to suggest a possible approach for implementing it.

Best wishes,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ryan
Top achievements
Rank 2
answered on 03 Oct 2011, 03:35 PM
Basically I just want the control to display the red border and display the red tooltip. I have two types of validation needed for this field: one to make it a required field; the other is to make a valid selection which 3-4 levels deep in the hierarchy.
0
Accepted
Zarko
Telerik team
answered on 04 Oct 2011, 09:47 AM
Hi Ryan,
In the latest internal build - 2011.2.1003 the CurrentItem property is no longer readonly so you can bind it to some business property in your ViewModel. At the moment you can bind to the Path property and do the validation there.
The IDataErrorInfo in supported out of the box only by some microsoft controls (e.g. textbox, datagrid) and the RadBreadcrumb doesn't so you'll have to create your custom validation (a red border around the breadcrumb which visibility/opacity is bound to your viewmodel maybe).
If you have more questions please feel free to ask.

Kind regards,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stefan
Top achievements
Rank 1
answered on 25 Nov 2011, 01:27 PM
Hi Zarko,

I am also using your new Breadcrum control in our project and I would like to bind the CurrentItem property to a property on my view model. Unfortunately it only works if you set the very first item of my items source collection. If you take any other one, the exception below is thrown. I guess there is some bug in the FindCurrentItemRecursively method. I tried debugging this issue, unfortunately I don't have the right symbols and somehow the decompiled sources of Resharper don't seem to match the actual executed version, so I can't really see what your code is doing there. Could you please have a look, if you could fix that issue before your release next week, as it would save me quite some time on working around this.

Thanks a lot for your help,

Best Greetings, Stefan

at Telerik.Windows.Controls.RadBreadcrumb.FindCurrentItemRecursively(String currentPath, IEnumerable items, Object searchValue) in c:\TB\117\WPF_Scrum\Current_HotFix\Sources\Development\Controls\Navigation\Breadcrumb\RadBreadcrumb.cs:line 919
at Telerik.Windows.Controls.RadBreadcrumb.FindCurrentItemRecursively(String currentPath, IEnumerable items, Object searchValue) in c:\TB\117\WPF_Scrum\Current_HotFix\Sources\Development\Controls\Navigation\Breadcrumb\RadBreadcrumb.cs:line 931
at Telerik.Windows.Controls.RadBreadcrumb.FindCurrentItem(Object newValue) in c:\TB\117\WPF_Scrum\Current_HotFix\Sources\Development\Controls\Navigation\Breadcrumb\RadBreadcrumb.cs:line 914
at Telerik.Windows.Controls.RadBreadcrumb.OnCurrentItemChanged(Object oldValue, Object newValue) in c:\TB\117\WPF_Scrum\Current_HotFix\Sources\Development\Controls\Navigation\Breadcrumb\RadBreadcrumb.cs:line 583
at Telerik.Windows.Controls.RadBreadcrumb.OnCurrentItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\TB\117\WPF_Scrum\Current_HotFix\Sources\Development\Controls\Navigation\Breadcrumb\RadBreadcrumb.Properties.cs:line 476
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.UIElement.UpdateLayout()
at System.Windows.Interop.HwndSource.SetLayoutSize()
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
at System.Windows.Window.SourceWindowHelper.set_RootVisual(Visual value)
at System.Windows.Window.SetRootVisual()
at System.Windows.Window.SetRootVisualAndUpdateSTC()
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()

One more thing, I just had the idea it might be the problem that I am binding collections of different types on different levels of the hierarchy, so it might be that your FindCurrentItemsRecursively method has problems with that? Here's the markup code, maybe that helps you to understand our binding scenario.

<telerik:RadBreadcrumb Header="Alle Listen"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Top"
                       Margin="0 0 0 10"
                       IsTextModeEnabled="False"
                       ItemsSource="{Binding TemplateSelectionModuleViewModels}"
                       CurrentItem="{Binding CurrentItem, Mode=TwoWay}">
    <telerik:RadBreadcrumb.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding TemplateViewModels}">
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
    </telerik:RadBreadcrumb.ItemTemplate>
</telerik:RadBreadcrumb>
0
Stefan
Top achievements
Rank 1
answered on 25 Nov 2011, 01:43 PM
Hi Zarko one more time.

I checked one more time your source and it looks like the GetItemChildren(object currentItem) method returns null if the currentItem is a leave. The return value is used after as input (items parameter) for the recursive call to FindCurrentItemRecursively, which after results in a NullReferenceException when iterating over the items. Guess I can work around that issue at the moment by just binding an empty collection to my leaves, would be nice anyway, if you could fix this. Thanks for your help.

Stefan
 
0
Stefan
Top achievements
Rank 1
answered on 25 Nov 2011, 02:27 PM
Hi Zarko,

I investigated a bit more and it actually looks like the GetItemChildren method does not work at all in my binding scenario, it simply checks the HierarchicalItemsSource Property, which is null in my case and then it doesn't find any children for the first hierarchy level already, so that's why it's returning null. So providing an empty collection on the leaves doesn't fix the issue. If I try to set the HierarchicalItemSource so it could find some children, it crashes even before:

System.InvalidOperationException : You can't use both ItemTemplate and HierarchicalItemsSource.

So I guess my binding scenario is not yet working in your current build. Do you plan to implement this till to your next release?

Thanks a lot for your help, Stefan
0
Zarko
Telerik team
answered on 30 Nov 2011, 02:11 PM
Hello Stefan,
Thank you for the feedback! There really seems to be a problem in the GetItemChildren method when you're using a HierarchicalDataTemplate.
For now I can give you a work around - instead of a HierarchicalDataTemplate you can use the Breadcrumb properties (HeaderMemberPath, HierarchicalMemberPath and HierarchicalItemsSource).
I've logged this issue in our PITS under the name "CurrentItem doesn't work correctly when used with HierarchicalDataTemplate" and it'll be ready for tracking tomorrow the lastest. I've also updated your telerik account and attached a sample project so you could examine it.
If you have more questions please feel free to ask.

Kind regards,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stefan
Top achievements
Rank 1
answered on 16 Dec 2011, 05:37 PM
Hi Zarko,

Thank you, that does the job, as long as you don't have more than three different view model types, so for our case that's working.

Best greetings, Stefan
0
Stefan
Top achievements
Rank 1
answered on 16 Dec 2011, 05:40 PM
I don't find the issue in your PITS.
0
Zarko
Telerik team
answered on 19 Dec 2011, 09:55 AM
Hello Stefan,
I'm sorry for the misunderstanding - it seems that I've logged this issue as private and that's why you couldn't find it. I changed it to public and this is the link to it.
If you have more questions please feel free to ask.

Greetings,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stefan
Top achievements
Rank 1
answered on 09 Jan 2012, 10:07 AM
Thank you!
Tags
BreadCrumb
Asked by
Ryan
Top achievements
Rank 2
Answers by
Tina Stancheva
Telerik team
Ryan
Top achievements
Rank 2
Zarko
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or