Click here to Skip to main content
15,909,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone.

I created a ListBox Custom Control in WPF and would like to know how I can display an Image in every row of the ListBox.

I got this so far:

XML
<Style TargetType="{x:Type local:CustomList}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomList}">
                    <Border Name="BorderOfList"
                            removed="LightGray"
                            BorderBrush="Black"
                            BorderThickness="1"
                            CornerRadius="2">
                        <ScrollViewer Focusable="False">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Grid.Column="0">
                                    <ItemsPresenter/>
                                    <Image Source="/Pictures/1.png"/>
                                </StackPanel>
                            </Grid>
                        </ScrollViewer>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="BorderOfList"
                                    Property="Background" 
                                    Value="Aqua"/>
                            <Setter TargetName="BorderOfList"
                                    Property="BorderBrush"
                                    Value="BlueViolet"/>
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="True">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="True">
                            <Setter TargetName="BorderOfList" Property="Background" Value="LightGreen"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


If you need any more details, please let me know.

Thanks in advance.
Posted
Comments
blitzkrieged 17-Sep-13 16:17pm    
Use a ListView and look into setting the SmallImageList/LargeImageList.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900