ViewModel Binding Not Working on Telerik Window

2 posts, 0 answers
  1. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 13 Jan 2010 Link to this post

    I have a silverlight UserControl that is bound to a ViewModel. If I place a RadWindow in the UserControl and then place other controls within the RadWindow then none of my binding's work. If I comment out the RadWindow begin and end tags then the bindings work correctly. This unfortunately leaves me with no popup window. Here is the XAML that does not work with my bindings. I have tried removing the DataContext="{Binding}" with no success. I am using release 2009.3.1103.1030.
    <telerikRadWindow:RadWindow x:Name="_newUserDialog" DataContext="{Binding}" Margin="10" Grid.Row="3" Background="#CFEEF5" Header="Add New User" WindowStartupLocation="CenterScreen" > 
                <Grid Margin="5" Name="_newUserGrid" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed"
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <RowDefinition Height="Auto"/> 
                        <ColumnDefinition Width="Auto" /> 
                        <ColumnDefinition Width="200" />                                         
                    <TextBlock Margin="0,5,0,5" Text="First Name:" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" Foreground="#FF329B24" /> 
                    <TextBox Margin="0,5,0,5" Text="{Binding WorkingUser.FirstName, Mode=TwoWay}"  Grid.Row="0" Grid.Column="1" /> 
                    <TextBlock Margin="0,5,0,5" Text="Last Name:" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Foreground="#FF329B24" /> 
                    <TextBox Margin="0,5,0,5" Text="{Binding WorkingUser.LastName, Mode=TwoWay}"  Grid.Row="1" Grid.Column="1" /> 
                    <TextBlock Margin="0,5,0,5" Text="User Name:" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" Foreground="#FF329B24" /> 
                    <TextBox Margin="0,5,0,5" Text="{Binding WorkingUser.UserName, Mode=TwoWay}"  Grid.Row="2" Grid.Column="1" /> 
                    <TextBlock Margin="0,5,0,5" Text="Password:" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Foreground="#FF329B24" /> 
                    <TextBox Margin="0,5,0,5" Text="{Binding WorkingUser.Password, Mode=TwoWay}"  Grid.Row="3" Grid.Column="1" /> 
                    <TextBlock Margin="0,5,0,5" Text="SSN#:" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0" Foreground="#FF329B24" /> 
                    <TextBox Margin="0,5,0,5" Text="{Binding WorkingUser.SocialSecurityNumber, Mode=TwoWay}"  Grid.Row="4" Grid.Column="1" /> 
                    <TextBlock Margin="0,5,0,5" Text="User Type:" VerticalAlignment="Center" Grid.Row="5" Grid.Column="0" Foreground="#FF329B24" />              
                    <ComboBox Margin="0,5,0,5" Height="24" ItemsSource="{Binding UserTypes}" DisplayMemberPath="Name" SelectedItem="{Binding WorkingUser.UserType, Mode=TwoWay}" Grid.Row="5" Grid.Column="1" /> 
                    <Grid Grid.Row="6" Grid.ColumnSpan="3"
                            <RowDefinition Height="Auto" /> 
                            <RowDefinition Height="200" /> 
                        <TextBlock Text="Select the providers for which this user has access."/> 
                        <ScrollViewer Name="_providerDialogScrollViewer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
                            <ItemsControl ItemsSource="{Binding Providers}"
                                        <CheckBox Content="{Binding Name}" IsChecked="{Binding IsAssociatedWithProvider}" /> 
                    <StackPanel Grid.Row="7" Grid.Column="2"  Orientation="Horizontal" Margin="0,5,0,0" HorizontalAlignment="Right"
                        <Button  Name="_saveButton" Style="{StaticResource DefaultButtonStyle}" Content="Save" /> 
                        <Button Name="_cancelButton" Style="{StaticResource DefaultButtonStyle}" Margin="10,0,10,0" Content="Cancel"/> 

  2. Miroslav Nedyalkov
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 14 Jan 2010 Link to this post

    Hello Billy,

     Unfortunately the expression DataContext="{Binding}" will not work when the RadWindow is shown (its Show or ShowDialog methods are called), because it will be removed from the VisualTree and the inhereted DataContext property will be lost. What I could suggest you as work-around is to add ElementName to this binding and to point one of the parents of the RadWindow.

    If you have further questions, don't hesitate to ask.

    Sincerely yours,
    Miroslav Nedyalkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top