WPF的ListBox的数据绑定,但需要添加控件在里面的时候

    或许有时候你会想要设置出像asp.net中的绑定控件一样设置出漂亮的样式来,但是使用的控件呢?DataGrid的?不行,设置出来的样式简直没办法看啊,所以大家很多时候还是会选择ListBox,

不错这是一个很好用的控件,我们只要使用的DateTemplate模板那就能解决样式的问题了。

 

<page.Resources>
       
<!--DataTemplate-->
      
 <DataTemplate x:Key="TypeTemplate">

在此处你可以随意的设置你想要的样式,这样很好用,有木有?

            <StackPanel Orientation="Vertical">

                <Button Margin="0,-5,0,0" Content="{Binding CodeName}" ></Button>

            </StackPanel>
       
</DataTemplate>
   
</Page.Resources>
 

<ListBox Grid.Row="1" Width="260" ItemsSource="{Binding TypeList}"  ItemTemplate="{StaticResource TypeTemplate}" ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"></ListBox>

 

posted @ 2012-03-02 19:06  静艳  阅读(1254)  评论(0编辑  收藏  举报