通过扩展Listview控件创建列表视图

通过扩展Listview控件创建列表视图

问题描述:

想要通过扩展listview控件来创建列表视图。我必须为自定义列表视图创建一个独特的样式。我面临的问题是

当我使用gridview来安排数据时,我应用的样式会丢失,它看起来就像普通的列表视图。



这里我展示了我试过的一些样本。



在我设计列表视图的Xaml文件中





Want to create a listview by Extending the The listview control. I have to create a unique style for my custom listview. The problem I am facing is
when am putting a gridview to arrange the data, the style that i applied will loss and it wil look like the ordinary listview.

Here i am displaying some of the sample that i tried.

In the Xaml file where i designed my listview


<Style TargetType="{x:Type local:GOGWPFAdvancedListView}">
     <Setter Property="Template">
         <Setter.Value>
             <ControlTemplate TargetType="{x:Type local:GOGWPFAdvancedListView}">
                 <Border removed="LightBlue"
                         BorderBrush="Blue"
                         BorderThickness="10">
                 </Border>
             </ControlTemplate>
         </Setter.Value>
     </Setter>
 </Style>



我为我的列表视图扩展了一个课程



public class GOGWPFAdvancedListView:System.Windows.Controls.ListView

{

static GOGWPFAdvancedListView()

{

DefaultStyleKeyProperty。 OverrideMetadata(typeof(GOGWPFAdvancedListView),新的System.Windows.FrameworkPropertyMetadata(typeof(GOGWPFAdvancedListView)));



}

}



在我的消费页面中



xmlns:Advanced =clr-namespace:GOGWPFAdvancedListView; assembly = GOGWPFAdvancedListView





当我只放置新的控件时它的风格是可见的


I Extended a class for my listview

public class GOGWPFAdvancedListView : System.Windows.Controls.ListView
{
static GOGWPFAdvancedListView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GOGWPFAdvancedListView), new System.Windows.FrameworkPropertyMetadata(typeof(GOGWPFAdvancedListView)));

}
}

In my Consuming Page

xmlns:Advanced="clr-namespace:GOGWPFAdvancedListView;assembly=GOGWPFAdvancedListView"


when i put only the new control its style is visible

<advanced:gogwpfadvancedlistview name="lvMainlist" >
</advanced:gogwpfadvancedlistview>







但是当我把一个gridview放到listview上时它会看起来像普通的listview






But when i put a gridview to the listview it wil look like the ordinary listview

<advanced:gogwpfadvancedlistview name="lvMainlist" >
           <advanced:gogwpfadvancedlistview.view>
                <gridview>
                    <gridviewcolumn header="Name" width="100" displaymemberbinding="{Binding Name}" />
                    <gridviewcolumn header="Place" width="100" displaymemberbinding="{Binding Place}" />
                    <gridviewcolumn header="Country" width="100" displaymemberbinding="{Binding Country}" />
                    <gridviewcolumn header="State" width="100" displaymemberbinding="{Binding State}" />
                    <gridviewcolumn header="Age" width="100" displaymemberbinding="{Binding Age}" />
                    <gridviewcolumn header="C/O" width="100" displaymemberbinding="{Binding CO}" />
                    <gridviewcolumn header="JOB" width="100" displaymemberbinding="{Binding JOB}" />
                </gridview>
            </advanced:gogwpfadvancedlistview.view>
        </advanced:gogwpfadvancedlistview>







任何建议???




Any suggestions???

快速查看后我认为你缺少一个TemplateBinding,当你设置ListView的内容时,它应该将它设置为ControlTemplate中边框的内容,不应该'是吗?
After a quick look I think you are missing a TemplateBinding, when you set the Content of your ListView it should set it to the Content of your border in the ControlTemplate, shouldn't it?