This is a migrated thread and some comments may be shown as answers.
ViewModel Binding Not Working on Telerik Window
1 Answer 47 Views
This is a migrated thread and some comments may be shown as answers.
StevenDale
Top achievements
Rank 2
StevenDale asked on 14 Jan 2010, 04:03 AM
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"
                <Grid.RowDefinitions>                     
                    <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"/> 
                </Grid.RowDefinitions> 
                <Grid.ColumnDefinitions> 
                    <ColumnDefinition Width="Auto" /> 
                    <ColumnDefinition Width="200" />                                         
                </Grid.ColumnDefinitions> 
                <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"
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="Auto" /> 
                        <RowDefinition Height="200" /> 
                    </Grid.RowDefinitions> 
                    <TextBlock Text="Select the providers for which this user has access."/> 
                    <ScrollViewer Name="_providerDialogScrollViewer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
                        <ItemsControl ItemsSource="{Binding Providers}"
                            <ItemsControl.ItemTemplate> 
                                <DataTemplate> 
                                    <CheckBox Content="{Binding Name}" IsChecked="{Binding IsAssociatedWithProvider}" /> 
                                </DataTemplate> 
                            </ItemsControl.ItemTemplate> 
                        </ItemsControl> 
                    </ScrollViewer> 
                </Grid> 
                 
                 
                <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"/> 
                </StackPanel> 
            </Grid> 
        </telerikRadWindow:RadWindow> 

1 Answer, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 14 Jan 2010, 12:18 PM
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.
Asked by
StevenDale
Top achievements
Rank 2
Answers by
Miroslav Nedyalkov
Telerik team
Share this question
or