Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

c# - WPF: ListView with icons view?

I can't figure out how I can implement an Icon View in the WPF ListView (a view similar to the Windows Explorer). Searching on google I only found informations about implementing the GridView but no clues about the Icon View. I'm not talking about System.Windows.Form.ListView but System.Windows.Controls.ListView.

Perhaps there is another control to do that? I didn't find anything relevant about this?

I've only found some people that build the icon view by hand using the listbox and changing the paneltemplate and the icontemplate. I can't believe this is the only way to do it.

Any clues?

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EDIT Appears i misunderstood what you meant with Explorer view...i have mine set to Details... ;) I'll leave my answer up here in case anyone makes the same mistake as i...


There is no such thing as an Icon View in WPF, you'll have to implement it yourself, but you dont have to do everything from scratch.

You can use the ListView in combination with a GridView and at least one CellTemplate for the column that contains the icon.

The general outline would look something like this for an Windows Explorer like view:

<ListView>
    <ListView.Resources>
        <DataTemplate x:Key="IconTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0"/>
                <TextBlock Grid.Column="1" Text="{Binding Name}"/>
            </Grid>
        </DataTemplate>
    </ListView.Resources>            
    <ListView.View>     
        <GridView>
            <GridViewColumn CellTemplate="{StaticResource IconTemplate}" Header="Name"/>
            <GridViewColumn DisplayMemberBinding="{Binding Size}" Header="Size"/>
            <GridViewColumn DisplayMemberBinding="{Binding Type}" Header="Type"/>                    
        </GridView>
    </ListView.View>
</ListView>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...