How to display some text depending on if a file is selected

3 posts, 1 answers
  1. Kirk Quinbar
    Kirk Quinbar avatar
    48 posts
    Member since:
    Nov 2007

    Posted 17 Dec 2010 Link to this post

    In the attached image you will see how I want the second radupload control to look like. when no files are selected, i wanted to display some gray text ("optional" in this case), kinda like the EmptyContent that is on your maskededitcontrol. From what i can tell, I thought that I would do this in the style i can apply to the RadUpload control in the rootelement section as shown below. So i was just going to use a TextBlock right by the ItemsPresenter. The issue I have is i need to show or not show that textblock depending on if a file has been selected by the user. Is there something i could bind to the Visibility (thru a converter probably?) property of the textblock at this point in the style that would allow this? or is there a better way to accomplish what i want?

    <Grid x:Name="RootElement" VerticalAlignment="Center">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Border 
                                        Grid.Column="0" 
                                        BorderThickness="1" 
                                        Background="#FFFFFFFF"
                                        Padding="2" 
                                        CornerRadius="2"
                                        VerticalAlignment="Top" 
                                        Height="24"
                                        MinWidth="300">
                                        <Grid VerticalAlignment="Top" HorizontalAlignment="Left">
                                            <TextBlock Text="optional" FontStyle="Italic" Foreground="Gray" />
                                            <ItemsPresenter VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                        </Grid>
                                    </Border>
                                    <telerik:RadButton 
                                        x:Name="BrowseButton" 
                                        Grid.Column="1" 
                                        HorizontalAlignment="Left" 
                                        VerticalAlignment="Center" 
                                        Margin="-5,0,0,0"
                                        Content="{Binding ShellResource.BrowseButton, Source={StaticResource Localization}}" 
                                        Style="{StaticResource Button_Main}" />
                                </Grid>
  2. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 20 Dec 2010 Link to this post

    Hi Kirk Quinbar,

    The RadUpload is an ItemsControl (ListBox), so you can bind to its Items.Count property and display the empty content with a IValueConverter. The CaptionText is another option as when there are no files selected, it would be "Select Files To Upload", so you can bind to it as well.

    Regards,
    Alex Fidanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Kirk Quinbar
    Kirk Quinbar avatar
    48 posts
    Member since:
    Nov 2007

    Posted 20 Dec 2010 Link to this post

    Thanks! that works perfect. For anyone interested my code is below. I added a textblock right before the ItemsPresenter so i could show basically like a watermark in the radupload when nothing is selected. it just displays "optional" to my users.


    <Grid x:Name="RootElement" VerticalAlignment="Center">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Border 
                                        Grid.Column="0" 
                                        BorderThickness="1" 
                                        Background="#FFFFFFFF"
                                        Padding="2" 
                                        CornerRadius="2"
                                        VerticalAlignment="Top" 
                                        Height="24"
                                        MinWidth="300">
                                        <Grid VerticalAlignment="Top" HorizontalAlignment="Left">
                                            <TextBlock Text="optional" Visibility="{Binding Items.Count, Converter={StaticResource CountToVisibility}, RelativeSource={RelativeSource Mode=TemplatedParent}}" FontStyle="Italic" Foreground="Gray" />
                                            <ItemsPresenter VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                        </Grid>
                                    </Border>
                                    <telerik:RadButton 
                                        x:Name="BrowseButton" 
                                        Grid.Column="1" 
                                        HorizontalAlignment="Left" 
                                        VerticalAlignment="Center" 
                                        Margin="-5,0,0,0"
                                        Content="{Binding ShellResource.BrowseButton, Source={StaticResource Localization}}" 
                                        Style="{StaticResource Button_Main}" />
                                </Grid>
Back to Top