DefaultImagesSrc image sizing problem

2 posts, 1 answers
  1. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 10 Apr 2011 Link to this post

    Hello.

    I'm adding an image to my treeview using the "DefaultImagesSrc" property and the ImagesBaseDir property. The image displays, but significantly smaller than it should. I tried setting the height and width properties for the radtreeviewitem to be the size of the image but that didn't work. When I drop an image control onto the xaml and set it to the same image, it displays in the proper size. What am I doing wrong?

    <telerik:RadTreeView Height="250" HorizontalAlignment="Left" Margin="12,32,0,0" Name="tvDirectories" VerticalAlignment="Top" Width="364" ItemsSource="{Binding ElementName=radTreeView1, Path=Background}" ImagesBaseDir="/UploadDocFromPDFWPF;component/Images/" ItemPrepared="radTreeView_ItemPrepared">
        <telerik:RadTreeViewItem DefaultImageSrc="mycomputer.png"></telerik:RadTreeViewItem>
    </telerik:RadTreeView>

    Again, if I create a standard image control and use the same image it displays using the proper size.
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 13 Apr 2011 Link to this post

    Hi fred williams,

    Probably you will have to edit the control template  of the RadTreeViewItem and increase  the MaxHeight , MaxWidth of the Image which are set to 16.
    <telerik:RadTreeViewItem Template="{StaticResource RadTreeViewItemControlTemplate1}" />
    <ControlTemplate x:Key="RadTreeViewItemControlTemplate1" TargetType="{x:Type telerik:RadTreeViewItem}">
                <Grid x:Name="RootElement">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid x:Name="HeaderRow" Background="Transparent" MinHeight="{TemplateBinding MinHeight}" SnapsToDevicePixels="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="2"/>
                        <Border x:Name="MouseOverVisual" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Opacity="0">
                            <Border BorderBrush="White" BorderThickness="1" CornerRadius="0">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFFFFBA3" Offset="1"/>
                                        <GradientStop Color="#FFFFFBDA" Offset="0"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </Border>
                        <Border x:Name="SelectionUnfocusedVisual" BorderBrush="#FFDBDBDB" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Visibility="Collapsed">
                            <Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="0">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0,1">
                                        <GradientStop Color="#FFF8F6F9" Offset="0"/>
                                        <GradientStop Color="#FFF0F0F0" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </Border>
                        <Border x:Name="SelectionVisual" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Visibility="Collapsed">
                            <Border BorderBrush="White" BorderThickness="1" CornerRadius="0">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFFCE79F" Offset="1"/>
                                        <GradientStop Color="#FFFDD3A8"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </Border>
                        <StackPanel x:Name="IndentContainer" Orientation="Horizontal">
                            <Rectangle x:Name="IndentFirstVerticalLine" Stroke="#FFCCCCCC" Visibility="Collapsed" VerticalAlignment="Top" Width="1"/>
                        </StackPanel>
                        <Grid x:Name="ListRootContainer" Grid.Column="1" HorizontalAlignment="Center" MinWidth="20">
                            <Rectangle x:Name="HorizontalLine" HorizontalAlignment="Right" Height="1" Stroke="#FFCCCCCC" VerticalAlignment="Center"/>
                            <Rectangle x:Name="VerticalLine" HorizontalAlignment="Center" Stroke="#FFCCCCCC" VerticalAlignment="Top" Width="1"/>
                            <ToggleButton x:Name="Expander" Background="{TemplateBinding Background}" IsTabStop="False"/>
                            <Grid x:Name="LoadingVisual" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed" VerticalAlignment="Center">
                                <Grid.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform Angle="0" CenterY="0.5" CenterX="0.5"/>
                                    </TransformGroup>
                                </Grid.RenderTransform>
                                <Path Data="M1,0A1,1,90,1,1,0,-1" Height="10" StrokeStartLineCap="Round" Stretch="Fill" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Width="10"/>
                                <Path Data="M0,-1.1L0.1,-1 0,-0.9" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left" Height="4" Margin="5,-1.5,0,0" Stretch="Fill" StrokeThickness="1" VerticalAlignment="Top" Width="4"/>
                            </Grid>
                        </Grid>
                        <CheckBox x:Name="CheckBoxElement" Grid.Column="2" IsTabStop="False" Margin="5,0,0,0" Visibility="Collapsed" VerticalAlignment="Center">
                            <telerik:StyleManager.Theme>
                                <telerik:Office_BlackTheme/>
                            </telerik:StyleManager.Theme>
                        </CheckBox>
                        <RadioButton x:Name="RadioButtonElement" Grid.Column="2" IsTabStop="False" Margin="5,0,0,0" Visibility="Collapsed" VerticalAlignment="Center">
                            <telerik:StyleManager.Theme>
                                <telerik:Office_BlackTheme/>
                            </telerik:StyleManager.Theme>
                        </RadioButton>
                        <Image x:Name="Image" Grid.Column="3" HorizontalAlignment="Center" MaxWidth="16" MaxHeight="16" Margin="2" VerticalAlignment="Center"/>
                        <Rectangle x:Name="FocusVisual" Grid.ColumnSpan="6" Grid.Column="2" IsHitTestVisible="False" RadiusY="3" RadiusX="3" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2" Visibility="Collapsed"/>
                        <Grid Grid.ColumnSpan="2" Grid.Column="4">
                            <ContentPresenter x:Name="Header" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <ContentPresenter x:Name="EditHeaderElement" ContentTemplate="{TemplateBinding HeaderEditTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                    </Grid>
                    <ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Visibility="Collapsed"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsInEditMode" Value="True">
                        <Setter Property="Visibility" TargetName="Header" Value="Collapsed"/>
                        <Setter Property="Visibility" TargetName="EditHeaderElement" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Visibility" TargetName="SelectionVisual" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Visibility" TargetName="FocusVisual" Value="Visible"/>
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsSelected" Value="True"/>
                            <Condition Property="IsSelectionActive" Value="False"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Opacity" TargetName="SelectionVisual" Value="0"/>
                        <Setter Property="Visibility" TargetName="SelectionUnfocusedVisual" Value="Visible"/>
                    </MultiTrigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" TargetName="Header" Value="0.5"/>
                    </Trigger>
                    <Trigger Property="IsExpanded" Value="True">
                        <Setter Property="Visibility" TargetName="ItemsHost" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsLoadingOnDemand" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard x:Name="LoadingVisualTransform">
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:1" From="0" RepeatBehavior="Forever" To="359" Storyboard.TargetProperty="Angle" Storyboard.TargetName="LoadingVisualAngleTransform"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <StopStoryboard BeginStoryboardName="LoadingVisualTransform"/>
                        </Trigger.ExitActions>
                        <Setter Property="Visibility" TargetName="LoadingVisual" Value="Visible"/>
                        <Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="IsDragOver" Value="True">
                        <Setter Property="Opacity" TargetName="MouseOverVisual" Value="1"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" SourceName="HeaderRow" Value="True">
                        <Setter Property="Opacity" TargetName="MouseOverVisual" Value="1"/>
                    </Trigger>
                </ControlTemplate.Triggers>


    All the best,
    Petar Mladenov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top