Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7567069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:34:19+00:00 2026-05-30T14:34:19+00:00

I made 2 Listviews 1 with an image + name & lastname and 1

  • 0

I made 2 Listviews 1 with an image + name & lastname and 1 that only display the images (in a Wrap panel in the listview). The first one:

  <ListView x:Name="lsvsomething" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" GotFocus="lsv_GotFocus" SelectionChanged="lsv_selectionchanged" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="auto">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Image HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Height="50" Source="{Binding image}" Stretch="Fill"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="auto" DisplayMemberBinding="{Binding name}">
                        <GridViewColumnHeader Content="name" Tag="name" Click="SortClick"/>
                    </GridViewColumn>
                    <GridViewColumn Width="auto" DisplayMemberBinding="{Binding lastname}">
                        <GridViewColumnHeader Content="lastname" Tag="lastname" Click="SortClick" />
                    </GridViewColumn>
                </GridView>
            </ListView.View>
    </ListView>

The second one(Only images):

 <ListView x:Name="lsvsomething" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" GotFocus="lsv_GotFocus" SelectionChanged="lsv_selectionchanged" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="60">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Image HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Height="50" Source="{Binding image}" Stretch="Fill"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
  </ListView>

Now they both have ListView.View in it, I want to put them in a “template?” in app.xaml, but I got no idea how I can do that. The 2nd Listview one also uses the ItemsPanelTemplate to make it a wrap panne. I found how I can save that one in app.xaml (ItemsPanel=”{DynamicResource somename}”) However I am using this listview on mutliple windows so I want to save them both(make templates of them both?) in the app.xaml file. Then I should also be able to switch them in runtime. (The itemsource is set in the “codebehind”)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:34:20+00:00Added an answer on May 30, 2026 at 2:34 pm

    “template” is indeed not exact definition. I assume you want to really want to have some sort of re-usability of the list views. There are few options

    Option 1 (preferred) Put each ListView in a UserControl. That would be a stand alone XAML file, with <UserControl> element at the root, and the <ListView> its only child (no need for panel since you have just one element. The XAML will look like:

    <UserControl x:Class="SO.NameAndImageList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="300"
        >
        <ListView ...>
            ...
        </ListView>
    </UserControl>
    

    To use this UserControl, define the ‘local’ namespace to point to your code, in put it:

    <Window ...
        xmlns:local"clr-namespace:SO">
    
        ...
        <local:NameAndImageList />
        ...
    </Window>
    

    Option 2 Create a DataTemplate, which presents a custom type that represents your list.

    In code (typically, this is called ViewModel, in a MVVM model), define the following type:

    public class PersonCollection : ObservableCollection<Person> { }
    

    Your type derives from ObservableCollection of Person (the class that contains the item), with no addition. This is just an alias XAML can understand. Then, in app.xaml file, within the <Application.Resources> section, define the following template:

    <DataTemplate TargetType="{x:Type local:PersonCollection}" x:Key="ImageAndNameTemplate">
        <ListBox ...>
            ...
        </ListBox>
    </DataTemplate>
    

    In order to reuse, just drop the PersonCollection data (typically, it will come from the DataContext) in any panel, or using binding within a ContentControl:

    <Window ... >
        <Window.DataContext>
            <!-- Instantiate the data. There are many other ways to do that -->
            <local:PersonCollection>
                <local:Person Name="..." Image="..." />
                <local:Person Name="..." Image="..." />
                <local:Person Name="..." Image="..." />
                ...
            </local:PersonCollection>
        </Window.DataContext>
    
        ...
        <ContentControl Content="{Binding}" ContentTemplate="{StaticResource ImageAndNameTemplate}" />
    
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView in which i have a function that creates images for
I've made a search screen that has one tab for keywords, filters, and a
I have made a program that list all files and folders(f&f) locating on sd
I made a listview that has three textviews and a checkbox and put it
I've made a ListView in my project, but I find that when I drag
I have made a ListView in my android application. But the problem is that
I got some questions about ListViews. first question : I got 5 listviews made
I'm creating a WPF application where several ListView selections are made in a row
Made solution change: I am trying to display a html table of data.. In
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.