ListBox inside a RadWindow

2 posts, 0 answers
  1. Michael
    Michael avatar
    5 posts
    Member since:
    Jan 2011

    Posted 17 May 2011 Link to this post

    I'm not sure if this is a telerik issue or just me being new and dumb to WP7....
    problem: I need to display a list of validation error objects inside a rad window when a user doesn't fill in a form properly.  The radwindow appears blank.

    here is the xaml
    <telerikPrimitives:RadWindow x:Name="window" WindowSizeMode="FitToPlacementTarget" >
                <Border BorderBrush="{StaticResource PhoneBorderBrush}"
                        BorderThickness="{StaticResource PhoneBorderThickness}">
                    <Grid Background="{StaticResource PhoneBackgroundBrush}">
                        <TextBlock Style="{StaticResource PhoneTextSmallStyle}" HorizontalAlignment="Left"
                                   Margin="27,128,0,0" Text="" Name="tbError"
                                   VerticalAlignment="Top" Foreground="#FF035D82" TextAlignment="Center"
                                   TextWrapping="Wrap"/>
     
                        <ListBox x:Name="lbErrors" Margin="0,0,-12,0" ItemsSource="{Binding valErrors}"  >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0,0,0,17" Width="432" Orientation="Vertical">
                                        <TextBlock x:Name="tbErrorMessage" Text="{Binding ErrorMessage}" Margin="12,-6,12,0" TextAlignment="Left" Style="{StaticResource PhoneTextSubtleStyle}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
     
                        <Button Content="ok" Click="CloseWindowClick"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Bottom"/>
                    </Grid>
                </Border>
            </telerikPrimitives:RadWindow>

    and the method from the cs page....
    public Registration()
    {
            InitializeComponent();
            DataContext = App.vmvalError;
    }

    }private bool FormIsValid()
            {
                bool isValid = true;
                List<valError> strErrors = new List<valError>();
     
                if (!(txtFirstName.Text.Length > 1) || !(txtLastName.Text.Length > 1))
                {
                    strErrors.Add(new valError("You must enter a first and last name."));
                    isValid = false;
                }
                if (!txtEmail.Text.Contains("@") || !txtEmail.Text.Contains(".") || !(txtEmail.Text.Length < 5))
                {
                    strErrors.Add(new valError("You must enter a valid email address."));
                    isValid = false;
                }
                if (!(txtUsername.Text.Length > 7) || !(pbPassword.Password.Length > 7) || !ContainsNumberAndLetter(txtUsername.Text) || !ContainsNumberAndLetter(pbPassword.Password))
                {
                    strErrors.Add(new valError("Your username and password most both contain at least 8 characters."));
                    isValid = false;
                }
     
                tbError.Text = "";
                if (isValid == false)
                {
                    this.window.IsOpen = true;
                    lbErrors.DataContext = strErrors;
                }
                else
                {
                    this.window.IsOpen = false;
                }
     
                return isValid;
            }
  2. Michael
    Michael avatar
    5 posts
    Member since:
    Jan 2011

    Posted 17 May 2011 Link to this post

    I figured it out, just changed the data source to a List<string> instead of a List of custom objects.  Not sure why I couldn't do it the other way....

    this is the xaml that worked for me
    <telerikPrimitives:RadWindow x:Name="window" WindowSizeMode="FitToPlacementTarget" >
               <Border BorderBrush="{StaticResource PhoneBorderBrush}"
                       BorderThickness="{StaticResource PhoneBorderThickness}">
                   <Grid Background="{StaticResource PhoneBackgroundBrush}">
                       <TextBlock Style="{StaticResource PhoneTextSmallStyle}" HorizontalAlignment="Left"
                                  Margin="27,128,0,0" Text="" Name="tbError"
                                  VerticalAlignment="Top" Foreground="#FF035D82" TextAlignment="Center"
                                  TextWrapping="Wrap"/>
     
                       <ListBox x:Name="lbErrors" Margin="0,0,-12,0" ItemsSource="{Binding}"  >
                           <ListBox.ItemTemplate>
                               <DataTemplate>
                                   <StackPanel Margin="0,0,0,17" Width="432" Orientation="Vertical">
                                       <TextBlock x:Name="tbErrorMessage" Text="{Binding}"
                                                  TextAlignment="Center" Padding="20" Style="{StaticResource PhoneTextSubtleStyle}"
                                                  TextWrapping="Wrap"/>
                                   </StackPanel>
                               </DataTemplate>
                           </ListBox.ItemTemplate>
                       </ListBox>
     
                       <Button Content="ok" Click="CloseWindowClick"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"/>
                   </Grid>
               </Border>
           </telerikPrimitives:RadWindow>
  3. DevCraft banner
Back to Top