This is a migrated thread and some comments may be shown as answers.

ListBox inside a RadWindow

1 Answer 82 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 17 May 2011, 04:16 PM
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;
        }

1 Answer, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 17 May 2011, 07:10 PM
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>
Tags
Window
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Share this question
or