[转帖] WPF Designer Guide to Style LiveView

[ReadMe] This article followed is referred from www.designerwpf.com/. All rights preserved.

So, after months of delay I finally figured that there are probably some people out there who want to figure out how to make the WPF listview look the way they want it to look.

A quick note: I will be dealing almost entirely with the listview look. If you want the listview to do something (functionality) or look a certain way and you can’t find the answer here, leave a comment with your suggestion and I’ll try to blog about it and place a link to the answer in my listview FAQ.

 

My goal is to create a significant repository on getting the stinking listview to look the way you want and do what you want it to do.

You’re probably here because, compared with most of the WPF controls, Blend gives very little guidance on how to deal with the listview (even though you use the listview for practically everything you do).  So we’re going to start with the basic structure of the listview. This is what the basic listview looks like in the XAML.

<ListView>
     
<ListView.View>
           
<GridView>
                 
<GridViewColumn Header=”Column Header/>
           
</GridView>
      
</ListView.View>
</ListView>

 

So this post will start out giving basic guidance on what to edit when you’re trying to edit the various parts of the listview. I will update these sections with links and tutorials on listview specific tasks as time goes on.

As a point of note, I recommend using an ItemSource for your listview when you’re learning ot style it. Manually putting ListViewItems into it and trying to style them will muddy the waters of good design. If you need a good ItemsSource, I recommend any of the New York Times RSS feeds.

How to connect the New York Times RSS feed to your listview

 

Question 1: “How do I make the items (see picture below) look the way I want them to?”

ListView_ItemContainerStyle

Answer: Use the ItemContainerStyle property in the ListView (and the associated ControlTemplate)

More on ItemContainerStyle and Blend

In the XAML:

Put this in the resources:
<Style x:Key=”MyItemContainerStyleTargetType=”{x:Type ListViewItem}>
</Style>

Put this in the composition:
<ListView ItemContainerStyle=”{DynamicResource MyItemContainerStyle}>

 

Question 2: “How do I make all the items in a certain column (see below) look a certain way?”

LV_CellTemplate

Answer: Use a CellTemplate in the GridViewColumn

More on CellTemplate and Blend.

In the XAML:

Put this in the resources:
<DataTemplate x:Key=”MyCellTemplate>
</DataTemplate>

Put this in the composition:
<GridViewColumn CellTemplate=”{DynamicResource MyCellTemplate}>

 

Question 3: “How do I make the whole header (see below) look the way I want?”

ListView_ColumnHeaderContainerStyle

Answer: Use the ColumnHeaderContainerStyle in the GridView (and the associated ControlTemplate)

More on the ColumnHeaderContainerStyle and Blend

In the XAML:

Put this in the resources:
<Style x:Key=”MyColumnHeaderContainerStyleTargetType=”{x:Type GridViewColumnHeader}>
</Style>

Put this in the composition:
<GridView ColumnHeaderContainerStyle=”{DynamicResource MyColumnHeaderContainerStyle}>

 

Question 4: “How do I change the layout of the header sections (all of them)?”

ListView_ColumnHeaderTemplate

Answer: Use a ColumnHeaderTemplate in the GridView

 How do I get to the ColumnHeaderTemplate using Blend? (coming soon)

In the XAML:

Put this in the resources:
<DataTemplate x:Key=”MyColumnHeaderTemplate>
</DataTemplate>

Put this in the composition:
<GridView ColumnHeaderTemplate=”{DynamicResource MyColumnHeaderTemplate}> 

Question 5: “How do I make a specific part of the header look different than another part?”
or “How do I make the red part look different than the blue part?”

 ListView_ColumnHeaderTemplate_better

Answer: Use the HeaderTemplate in the GridViewColumn

How do I get to the HeaderTemplate using Blend? (coming soon)

In the XAML:

Put this in the resources:
<DataTemplate x:Key=”MyHeaderTemplate>
</DataTemplate>

Put this in the composition:
<GridViewColumn HeaderTemplate=”{DynamicResource MyHeaderTemplate}>

 

Original url for your reference: http://www.designerwpf.com/2007/12/06/the-wpf-designers-guide-to-styling-the-your-favorite-adjectival-swear-word-here-listview/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值