SL4 data binding syntax issue (debugging declarative databinding) - silverlight

I'm using the DevExpress GridControl with a context menu. Their context menu implementation uses their bars control which creates a lose reference from a row in the grid to a group of reusable bars. What this means is the context menu items don't have the same context as the grid (sparing details).
I can bind the command (ala ICommand) property of the bar to a command I've creaed on my view model. The challenge is I can't get my syntax to work just right. The VM is set to the DataContext of the view, but something like this isn't workign (where the view's x:name is "VideoModulePage):
Command="{Binding Path=DataContext.ViewVideoCommand, ElementName=VideoModulePage}"
When I create this databinding expression in Blend/VS2010, it makes me thing this is valid, but the command isn't being fired. The CanExecute always returns true. Is this syntax valid? Any tips on a better approach to this? I think what I really need is the new SL5 databinding debugging now! :(
Here's a post I put in the DevExpress forum, but I don't think my issue is with their control, rather with my databinding syntax: http://community.devexpress.com/forums/t/96068.aspx

Related

Show a control in designer when the Visiblity's Fallbackvalue is set to 'Hidden'

in several Views we have container components - for example Grid or ScrollViewer- that are bound to a property on their own ViewModel or ViewModelItem.
In some cases the View (parent) containing these components can be shown without the ViewModel/ViewModelItem of the components being initialized. To avoid showing a user empty datagrids we are using FallBackValue=Hidden to make sure the container is only shown when it's ViewModel/ViewModelItem is initialized/loaded.
A hypothetical example would be a Window containing a DataGrid and a more detailed view to the right. The detailed view would be its own UserControl with its own ViewModel and the DataGrid would have its own ViewModel as well. When opening said Window the ViewModel of the DataGrid would be loaded immediately - but since no row has been selected the ViewModel that belongs to the detailed View would not be intialized, which means that the Visibility Binding of the detail View would fail and the binding's FallbackValue would be used to hide the detail View.
The issue with this approach is that the Visual Studio WPF/XAML designer will not show the content of the affected containers since they are hidden due to their FallbackValue.
Question: Is there a way to get the designer to show specific controls/components that have the FallBackValue of a Visibility binding set to Hidden? Clicking into the XAML code that is inside these hidden containers does not show them.
Edit 1
I found this answer. Setting d:IsHidden="false" does not help. Regardless of if it's set before or after the Visibility property.
When it comes to the designer you would have to set the Design Data Context.
To do that you would typically do the following in your xaml file:
<Control, Page or Window
xmlns:vm="clr-namespace:VM.ViewModel"
d:DataContext="{d:DesignInstance {x:Type vm:YourViewModelNameHere}, IsDesignTimeCreatable=True}"
.../>
However, sometimes like in your case, more flexibility is needed for the complex ViewModel. For this I would use Blend and it's functionality, what that is it will generate dummy data for you and set the data context of the Control for you.
For more information refer to this MSDN article.

How can you prevent a UserControl from being constructed when its parent is rendered?

I've been working to improve scrolling performance for an ItemsControl. Initially each item is a simple row of information and when an item is clicked, a detail UserControl is expanded below the item. I'm trying to eliminate the processing being done on the detail UserControl during scrolling. I eventually achieved this with a CustomControl, but I feel like I must be missing a simpler way to do it using the existing framework controls.
Initially, this detail view was a UserControl with Visibility.Collapsed. I should note that Virtualizing and Recycling are enabled for this ItemsControl. Therefore, scrolling performance was poor since each detail view was being bound to the data as the item scrolled into view, even though the detail was not visible.
I then tried using a ContentPresenter where the Content was bound to a DetailViewModel property and the ContentTemplate was set to a keyed DataTemplate. That DetailViewModel property was initialized to Nothing and then set to the appropriate ViewModel object when the item was clicked. This improved scrolling performance because there was no data binding, but I found that the detail UserControl was still getting constructed for each item, and I presume there was some rendering going on as well.
I eventually got the desired behavior with a custom ContentControl that provides dependency properties for GatedContentTemplate and IsGateOpen. When IsGateOpen goes True, the GatedContentTemplate is passed to the ContentTemplate property and the Content is set to the DataContext of the control, which causes the content to then get constructed, rendered, and bound.
<my:GatedContentControl IsGateOpen="{Binding IsDetailVisible}">
<my:GatedContentControl.GatedContentTemplate>
<DataTemplate>
<my:DetailUserControl/>
</DataTemplate>
</my:GatedContentControl.GatedContentTemplate>
</my:GatedContentControl>
I can live with this solution, but it's a little janky, and I wonder if I'm missing some way that WPF intends for this to be done.
Looks like I wasn't missing anything and this is a need that Microsoft is addressing in .net 4.6.
The Content Deferral feature is discussed in this video, starting at 26:30.
http://channel9.msdn.com/Events/dotnetConf/2015/WPF-in-46-and-beyond
Thanks for the comment HighCore.

Problem binding ICommand to event using ElementName within Pivot control

I am trying to hook up an ICommand on the model to a button within the ItemTemplate of a Pivot control.
To get a link to the parent model from within the ItemTemplate I usually use ElementName specifying the Name I provided for the xaml page.
This works when I use a ListBox to contain the items but not a pivot control.
Does any one have any ideas or come across this problem before?
Just noticed that if I define the PivotItems in xaml the Binding works. So it is only failing when I am dynamically populating the Pivot control.
UPDATE : OK So I'm beat with this now. I have linked the event to the models ICommand in the views code behind (nasty) and I'm going to look # this later. I will post my solution here once I have found it but any help would be great.
This is a know problem in Silverlight 3. Since, WP7 uses it right now, you will face the same thing with it as well.
To fix that, wrap your DataTemplate content that you put in your ItemTemplate into a UserControl.
Look into this question for further details.
WP7: Why does a ListBox.ItemsPanel break my ElementName data binding?

How To Perform Navigation In Silverlight 4.0 Using MVVM?

I'm new to Silverlight and I'm having trouble understanding how to properly navigate between pages, especially when I need to pass data around.
Classic example: I have a list of People on one page, and when I click on a person in the datagrid I'd like to go to the details page and load that data. I need to pass the PersonId. More importantly, I need to know how to do this from the ViewModel.
It's easy to fire a command from the datagrid that is on the ViewModel, and the SelectedItem on the viewmodel is also bound and thus tracked, but then what? How do I get to the next page? I can't for the life of me figure this one out. This seems like it should be really easy, but so far it's been anything but easy.
The most basic thing to do would be to change what Application.Current.RootVisual is set to and set the appropriate DataContext. However it is much better to have some wrappers that set this up properly for you. For example in your custom view that you are navigating to you can have the view's constructor handle some of that logic for you in a nicer way. If you are using Prism then you are ultimately talking about modifying the shell, or a container within the shell.
In the SelectedItemChanged you could set a ViewModel property "SelectedItem" with the object that you need in the other page. You ViewModel would need to be a Singleton. In the other page, you need to have the DataContext set to the ViewModel and now you can bind the SelectedItem to the control that you want.
The only thing that I do not like is that you still would need to go to the code behind of the starting page, get the SelectedItem from the DataGrid and set the ViewModel with this value.

Problem with data binding (Using the MVVM pattern) to a WPF Combobox within a DataGrid's RowDetailsTemplate

I'm trying to bind a view model property to the 'SelectedItem' attribute of a WPF combobox. This combobox resides within a RowDetailsTemplate of a DataGrid. The binding is partially there because the view model's property getter and setter each get called once when a row is selected (And thus causes the details view to expand). However the property never gets called again upon subsequent combobox selection changes. It's almost like the data context is not right after the row details is expanded or the binding is de-coupled after the row details is shown. Very strange, and I can't figure out how to get it to call the property upon all selection changes. There has to be a way.
I know this problem is due to the fact that the combobox is in the row details, but I can't figure out how to get it resolved. Has anybody ever had a problem similar to this? Any and I mean any kind of info or help would be much appreciated ... i've spent a few days hacking away at this trying to figure out why it's behaving this way.
Maybe the UpdateSourceTrigger in the Binding is not set to PropertyChanged?

Resources