WPF ListView控件布局自定义示例

WPF ListView控件布局自定义示例,第1张

概述kagula 2012-04-12 概要      以源码的形式贴出,免得忘记后,再到网上查资料。在VS2008+SP1环境下调试通过      引用的GrayscaleEffect模块,可根据参考资料《Grayscale Effect...》中的位置下载。 正文     如何布局是在App.xaml中定义源码如下 <Application x:Class="CWebsSynAssistant.A

kagula 2012-04-12

概要

     以源码的形式贴出,免得忘记后,再到网上查资料。在VS2008+SP1环境下调试通过

     引用的GrayscaleEffect模块,可根据参考资料《Grayscale Effect...》中的位置下载。

正文

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

<Application x:Class="CWebsSynAssistant.App"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                 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">                <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模块来源于下面的网址                        http://bursjootech.blogspot.com/2008/06/grayscale-effect-pixel-shader-effect-in.HTML                        -->                        <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" 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中定义源码如下

            <ListVIEw x:name="ListVIEw1" ItemTemplate="{StaticResource myLVItemTemplate}"                       Template="{StaticResource myLVTemplate}" ItemContainerStyle="{StaticResource ItemContainerStyle}"                      margin="0,4"   MouseDoubleClick="OnLocalFSOpen" GrID.Row="2">                <!--下面定义WarpPanel,使Item项在容器里从左到右从上到下排列-->                <ItemsControl.ItemsPanel>                    <ItemsPanelTemplate>                        <WrapPanel/>                    </ItemsPanelTemplate>                </ItemsControl.ItemsPanel>            </ListVIEw>
参考资料


>>WPF ListBox Tutorial
http://www.c-sharpcorner.com/uploadfile/mahesh/ListBox-in-wpf/
>>Drag and drop,cut/copy and paste files with windows Explorer
http://www.codeproject.com/Articles/14059/Drag-and-drop-cut-copy-and-paste-files-with-Window
>>Data Templating OvervIEw
http://msdn.microsoft.com/en-us/library/ms742521.aspx
>>WPF ListBox Selection color
http://stackoverflow.com/questions/794792/wpf-ListBox-selection-color
>>WPF Tutorial - Using The ListVIEw,Part 3 - In Place Edit
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-ListvIEw-part-3-in-place-edit
>>Creating a Custom Markup Extension in WPF (and soon,Silverlight)
http://10rem.net/blog/2011/03/09/creating-a-custom-markup-extension-in-wpf-and-soon-silverlight
>>More WPF Custom Effects: Motion Blur and Grayscale Samples
http://windowsclIEnt.net/wpf/wpf35/wpf-35sp1-more-effects.aspx
>>WPF Tutorial - Controls and Layout
http://www.mini.pw.edu.pl/~mossakow/materials/presentations/wpf.3.5/controls_layout/index.HTML
>>Grayscale Effect - A Pixel Shader Effect in WPF http://bursjootech.blogspot.com/2008/06/grayscale-effect-pixel-shader-effect-in.HTML >>ShaderPad - WPF ShaderEffects http://shaderpad.codeplex.com/

总结

以上是内存溢出为你收集整理的WPF ListView控件布局自定义示例全部内容,希望文章能够帮你解决WPF ListView控件布局自定义示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1068743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存