';视图不能由多个ListView共享';Wpf错误

';视图不能由多个ListView共享';Wpf错误,wpf,gridview,listview,Wpf,Gridview,Listview,这个代码有什么问题?它抛出异常:“视图不能由多个ListView共享” 错误是因为GridView应用于多个ListView。ListView样式是否应用于多个控件?我看了一下Reflector,看起来这个场景应该适用于单个控件 你到底想完成什么?我想你只是想展示不同的栏目。也许您可以创建一个附加的行为来为GridView生成列,具体取决于您要绑定到的属性的值。否我只有一个ListView,我在其中直接定义了样式。所有静态资源(GridViewBoth,…)都在UserControl的资源中定义

这个代码有什么问题?它抛出异常:“视图不能由多个ListView共享”


错误是因为GridView应用于多个ListView。ListView样式是否应用于多个控件?我看了一下Reflector,看起来这个场景应该适用于单个控件


你到底想完成什么?我想你只是想展示不同的栏目。也许您可以创建一个附加的行为来为GridView生成列,具体取决于您要绑定到的属性的值。

否我只有一个ListView,我在其中直接定义了样式。所有静态资源(GridViewBoth,…)都在UserControl的资源中定义。是的,你是对的,这正是我想要做的——根据属性显示不同的列。
<ListView 
    ItemsSource="{Binding}"  
    SelectionMode="Extended">
 <ListView.Style>

  <Style TargetType="ListView">   
   <Style.Triggers>
    <DataTrigger Binding="{Binding ElementName=MyControl, Path=IsCompany}" Value="True">
     <Setter Property="View" Value="{StaticResource GridViewCompanies}" />
    </DataTrigger>
    <DataTrigger Binding="{Binding ElementName=MyControl, Path=IsCompany}" Value="False">
     <Setter Property="View" Value="{StaticResource GridViewPeople}" />
    </DataTrigger>
    <DataTrigger Binding="{Binding ElementName=MyControl, Path=IsCompany}" Value="{x:Null}">
     <Setter Property="View" Value="{StaticResource GridViewBoth}" />
    </DataTrigger>
   </Style.Triggers>
  </Style>

 </ListView.Style>          
</ListView>

public bool? IsCompany
{
 get { return (bool?)GetValue(IsCompanyProperty); }
 set { SetValue(IsCompanyProperty, value); }
}        
public static readonly DependencyProperty IsCompanyProperty =
 DependencyProperty.Register("IsCompany", typeof(bool?), typeof(MyControl), new UIPropertyMetadata(null));
if() ..
MyListView.View = Resources["GridViewCompanies"] as GridView;