WPF: ListView with icons view?

前端 未结 4 517
深忆病人
深忆病人 2020-12-05 12:32

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 implem

相关标签:
4条回答
  • 2020-12-05 12:42

    Same as Tanveer Badar's answer, but with a WrapPanel instead of a UniformGrid. Set the following in your listbox:

    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
    ScrollViewer.VerticalScrollBarVisibility="Auto"       
    

    to force the WrapPanel to wrap.

    0 讨论(0)
  • 2020-12-05 12:48

    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>
    
    0 讨论(0)
  • 2020-12-05 12:49

    Just off the top of my head, have you tried this?

    <Style TargetType="ListBox">
      <Setter Property="ItemsPanel">
        <Setter.Value>
          <ItemsPanelTemplate>
            <UniformGrid/>
          </ItemsPanelTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    
    0 讨论(0)
  • 2020-12-05 12:49

    Here is another solution to the problem

    alt text http://blogs.msdn.com/photos/atc_avalon_team/images/585779/640x443.aspx

    0 讨论(0)
提交回复
热议问题