Difficulty binding a RadWindow with mvvm

10 posts, 0 answers
  1. Alan
    Alan avatar
    29 posts
    Member since:
    Feb 2008

    Posted 16 Jan 2011 Link to this post

    I am developing a Silverlight 4 application using MVVM and MEF that uses Q3 2010 RadControls.  I have a MainPage user control in the startup project in which I have defined several RadWindows for error, validation, deletion confirmation, etc.  I have created a Main Page view model which is set to the DataContext in the OnLoaded procedure.  The problem is that unlike other controls on the MainPage, the RadWindow bindings do not occur.  When I trace in debug, all the other controls, including some other types of RadControls such as RadMenu, set properties in the view model.  This does not happen with the RadWindows.  Some code snippets:

    <Grid x:Name="LayoutRoot"
        Background="{StaticResource AppBackgroundBrush}">
      
        <telerikNavigation:RadWindow x:Name="ValidationErrorWindow"                     Header="{Binding ResourceTitleValidationErrors}">
                <StackPanel>
                    <ItemsControl ItemsSource="{Binding ValidationErrors}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding ErrorContent}" />
                                    <Rectangle Style="{StaticResource SmallSpacerStyle}" />
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <Rectangle Style="{StaticResource StandardSpacerStyle}" />
                    <Button Content="{Binding ResourceCommandOK}"
                                    Command="{Binding CloseValidationWindowCommand}"
                                    HorizontalAlignment="Left"
                                    TabIndex="0" />
                </StackPanel>
            </telerikNavigation:RadWindow>
    Partial Public Class MainPage
        Public Sub New()
            InitializeComponent()
            'Me.loginContainer.Child = New LoginStatus()
            AddHandler Loaded, AddressOf OnLoaded
        End Sub
      
        Private Sub OnLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            CompositionInitializer.SatisfyImports(Me)
            DataContext = ViewModel
      
            AddHandler ViewModel.ConfirmDeletion, AddressOf OnConfirmDeletion
            AddHandler ViewModel.CloseConfirmDeletionWindow, AddressOf OnCloseConfirmDeletionWindow
    I have used the TaskIt sample application as a model and have implemented the RadWindows in a similar fashion to the TaskIt app in which this behavior does not occur. The Telerik dlls in the TaskIt app are an older version than what I am using.  Also, I am developing in VB whereas the TaskIt app was programmed in C#.  I have spent several days trying to resolve this issue which ultimately manifests itself as having RadWindow popup with no text or usable pushbuttons for commands.

    I am currently totally stymied by this and need help to resolve the issue.
  2. Alan
    Alan avatar
    29 posts
    Member since:
    Feb 2008

    Posted 17 Jan 2011 Link to this post

    I was able to work around the current behavior by explicitly setting, in the code behind, the DataContext of each of the RadWindows to the ViewModel used for the DataContext of the user control.  This does not appear to be the way it should be.
  3. DevCraft banner
  4. George
    Admin
    George avatar
    1332 posts

    Posted 20 Jan 2011 Link to this post

    Hello Alan,

     
    I would suggest you to place the RadWindow in a separate file. When the RadWindow opens, it goes out of the layout and it is not placed in the Grid anymore. Please, refer to the following link - http://www.telerik.com/help/silverlight/radwindow-how-to-use-radwindow-as-user-control.html

    All the best,
    George
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  5. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 02 Feb 2011 Link to this post

    Hello George. I did what the documentation suggested and still my RadWindow is not "binding" to either my Properties in my ViewModel or RelayCommand.

    I already posted a message here, but i just wanted you to know maybe you had a solution

    thank you

    http://www.telerik.com/community/forums/silverlight/window/radwindow-not-binding-to-viewmodel-mvvm-property-entity.aspx
  6. George
    Admin
    George avatar
    1332 posts

    Posted 07 Feb 2011 Link to this post

    Hello Jose,

    I will paste my answer here:

    I would suggest you to refer to the following blog post - http://blogs.telerik.com/blogs/posts/10-03-24/mvvm_in_task-it.aspx

    I hope this helps. 

    Kind regards,
    George
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  7. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Feb 2011 Link to this post

    Hello George,

    Thank you for your link. I read it and pretty much all my code is like that. But one detail i think is making a difference (or at least the only thing i think might help to my problem) is the part where in code-behind they pass a data to the Content?

    void OnItemSelected(object sender, RoutedEventArgs e)
    {
        // Show the form
        ContentControl1.Content = Details;
    }

    By the way, my whole code works like a charm. I am having a problem with the RadWindow only. It's not binding to my viewmodel at all. I practically have the same as in Task-It sample and i can't see why mine doesn't work and Task-It does. Can't see no difference.

    Can't believe i've spent a week trying to figure that out and no result. I am Disappointed at myself i guess.

    Happy San Valentine to you all!!!
  8. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Feb 2011 Link to this post

    I attached two screenshots. One from my code-behind where you can clearly see that the DataContext has the values i need and the XAML where the RadWindows are being used.

    I hope this helps a little bit.

    Thank You
  9. Alan
    Alan avatar
    29 posts
    Member since:
    Feb 2008

    Posted 14 Feb 2011 Link to this post

    I resolved my issue with RadWindow by explicitly setting the DataContext in the code behind to the ViewModel that applies.  The DataContext from the parent control does not seem to be flow down to the RadWindow controls so where I set the DataContext for my page, I also include a line for each RadWindow.  This has worked for me. 
  10. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Feb 2011 Link to this post

    Alan, that's what i did and while i was replying to your comment, i double check my XAML and i realized i had my DataContext being set there as well. I removed from the XAML and just left the one i was setting in the code-behind and now it works.

    I am half way happy thou. Not being able to get it the right way leaves me a sweet/soar taste. But, hey, time is money... gotta get this working. I'll do more research later but for now, it's working.

    I'll keep you posted if i find something.

    thank you and happy valentine.
  11. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Feb 2011 Link to this post

    One more thing. I noticed that if you set the specific Property (object) that you want to display values from, the viewmodel still would not trigger the commands. You need to set the whole viewmodel as the datacontext and then display the values using the Path.

    ex.
    <textblock text="{Binding Path=Customer.FirstName}" >

Back to Top
DevCraft banner