正文:

如何布局是在App.xaml中定义源码如下

<Application x:Class="CWebsSynAssistant.App"
  xmlns:effect="clr-namespace:GrayscaleEffect;assembly=GrayscaleEffect"
  StartupUri="Window1.xaml">
  <Application.Resources>
    <!-- ListView的布局模板-->
    <ControlTemplate x:Key="myLVTemplate" TargetType="{x:Type ListView}">
      <Grid>
        <ScrollViewer x:Name="ScrollViewerElement"
            Background="White"
            VerticalScrollBarVisibility="Auto"
            HorizontalScrollBarVisibility="Disabled">
          <ItemsPresenter>
          </ItemsPresenter>
        </ScrollViewer>
      </Grid>
    </ControlTemplate>
    <!-- ListViewItem的布局模板-->
    <DataTemplate x:Key="myLVItemTemplate">
      <Grid Name="myGrid" Width="70" Margin="8,8,0,0">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"></RowDefinition>
          <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <Image Name="img" Source="{Binding Path=ISource}" HorizontalAlignment="Center"
            Width="32" Height="32" Stretch="UniformToFill"
            ToolTip="{Binding Path=FullFileName}" >
          <Image.Effect>
            <effect:GrayscaleEffect x:Name="grayscaleEffect" DesaturationFactor="1.0"/>
          </Image.Effect>
        </Image>
        <TextBlock Name="imgTitle" Text="{Binding Path=FileName}" Grid.Row="1" HorizontalAlignment="Center"
              FontSize="10" FontFamily="Arial"
              ToolTip="{Binding Path=FullFileName}" Margin="4,4,4,4" TextTrimming="CharacterEllipsis" />
      </Grid>
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
          AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True">
          <Setter TargetName="myGrid" Property="Background" Value="White"/>
          <Setter TargetName="imgTitle" Property="Background" Value="CadetBlue"/>
          <Setter TargetName="imgTitle" Property="Foreground" Value="White"/>
          <Setter TargetName="img" Property="Effect">
            <Setter.Value>
              <effect:GrayscaleEffect DesaturationFactor="0.5"/>
            </Setter.Value>
          </Setter>
          <!--
          <Setter TargetName="img" Property="Opacity" Value=".5"></Setter>
          -->
        </DataTrigger>
      </DataTemplate.Triggers>
    </DataTemplate>
    <!--下面这段代码不用,选中的时候边框有些边会变成蓝色(不是你希望的颜色)-->
    <Style TargetType="{x:Type ListViewItem}" x:Key="ItemContainerStyle">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type ListViewItem}">
            <Border x:Name="Bd" Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" >
              <ContentPresenter/>
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsSelected" Value="true">
                <Setter Property="Background" TargetName="Bd" Value="White"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Application.Resources>
</Application>

如何引用在Windows1.xaml中定义源码如下

1
2
3
4
5
6
7
8
9
10
<ListView x:Name="listView1" ItemTemplate="{StaticResource myLVItemTemplate}"
     Template="{StaticResource myLVTemplate}" ItemContainerStyle="{StaticResource ItemContainerStyle}"
     Margin="0,4,0,4"  MouseDoubleClick="OnLocalFSOpen" Grid.Row="2">
  <!--下面定义WarpPanel,使Item项在容器里从左到右从上到下排列-->
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ListView>

最新文章

  1. RequireJS基础(三)
  2. bootstrap源码分析之form、navbar
  3. AI,DM,ML,PR的区别与联系
  4. ASP.NET MVC- 在Area里使用RedirectToAction跳转出错的解决方法
  5. 了解运行时类型信息(RTTI)
  6. 转:完善eclipse+pdt作php开发中的代码提示能力
  7. Unity跨平台原理
  8. Spring框架 jar包下载
  9. win8在安装office visio2003出现“请求的操作需要提升”,解决方法
  10. Java进阶(三十七)java 自动装箱与拆箱
  11. Java记事本编写第一个程序“你好,世界”
  12. Shell编程(三)Shell特性
  13. MySQL数据库之安装
  14. eclipse4.2版本下面安装ADT,安装已经完成了,但没有ADT的那个图标显示
  15. (一) 天猫精灵接入Home Assistant- hass对接天猫精灵
  16. 右键菜单添加git选项
  17. shell 函数调用
  18. 在Windows Phone项目中调用C语言DLL
  19. freemarker多个checkbox一个被选中示例
  20. Spring IoC入门

热门文章

  1. 三个div向左浮动不在同一行,向右浮动在同一行的解决办法
  2. 2016百度之星资格赛 Round1(2,3,4题)
  3. 项目中使用libsodium扩展
  4. (4)django mtv模式
  5. 8大排序算法的java实现--做个人收藏
  6. CSU 1505: 酷酷的单词【字符串】
  7. android wifi 调试
  8. struts2设置默认首页
  9. Hadoop Mapreduce分区、分组、二次排序过程详解
  10. java wait(),notify(),notifyAll()的理解