2017-08-21 8 views
0

データを表示するためにGridViewColumnsがいくつかあるWPFフォームがあります。ただし、各列にHeaderプロパティを設定しても、ヘッダーは表示されません。GridViewColumnHeaderが表示されない

XAML:

<Window x:Class="MyProject.ViewModel.MyClassView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:vm="clr-namespace:MyProject.ViewModel"   
     Title="Title" Height="210.4" Width="500" ResizeMode="NoResize" 
     WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"> 
    <Window.Resources> 
     <DataTemplate x:Key="tempA"> 
      <TextBlock Text="{Binding Path=dataA}"/> 
     </DataTemplate> 
     <DataTemplate x:Key="tempB"> 
      <TextBlock Text="{Binding Path=dataB}"/> 
     </DataTemplate> 
     <DataTemplate x:Key="tempC"> 
      <TextBlock Text="{Binding Path=dataC}"/> 
     </DataTemplate> 
    </Window.Resources> 
    <Grid Margin="5,5,5,5"> 
     <ListView x:Name="MyList" ItemsSource="{Binding MyDataCollection}" MouseDoubleClick="ListView_MouseDoubleClick"> 
      <ListView.View> 
       <GridView> 
        <GridViewColumn x:Name="colA" Header="Name" Width="100" CellTemplate="{StaticResource tempA}"/> 
        <GridViewColumn x:Name="colB" Header="Type" Width="100" CellTemplate="{StaticResource tempB}"/> 
        <GridViewColumn x:Name="colC" Header="Diameter" Width="100" CellTemplate="{StaticResource tempC}"/> 
       </GridView> 
      </ListView.View> 
     </ListView> 
    </Grid> 
</Window> 

コードビハインド:

namespace MyProject.ViewModel 
{ 
    public partial class MyClassView : Window 
    { 
     public object SelectedItem = null; 

     public MyClassView() 
     { 
      InitializeComponent(); 
     } 

     private void ListView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) 
     { 
      SelectedItem = MyList.SelectedItem; 
     } 
    } 
} 

のViewModel:

のViewModelコンストラクタに渡されるオブジェクトはDATAA、DATABを含むことが保証されて

namespace MyProject.ViewModel 
{ 
    public class MyViewModel : INotifyPropertyChanged 
    { 
     public string Type { get; set; } 
     public object MyDataCollection { get; set; } 

     public MyViewModel(object collection, string type) 
     { 
      Type = type; 
      MyDataCollection = collection; 
     } 

     internal void RaisePropertyChanged(string prop) 
     { 
      if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(prop)); } 
     } 
     public event PropertyChangedEventHandler PropertyChanged; 
    } 
} 
とデータC

誰かが私のGridViewのヘッダーが表示されない理由を説明できますか?

+0

が私のために列ヘッダは、コードごとに表示されます。

は、それは次のようになります。 –

+0

これは本当に多くありません...これは、別のウィンドウの子として生成されるスタンドアロンのウィンドウです。それに関連するコードはほとんどありません。コンストラクタやその他の変数定義です。 – bemailloux

+0

あなたが持っているすべてのコードを投稿 –

答えて

0

代わりにDataGridをお試しください。

<DataGrid ItemsSource="{Binding MyDataCollection}" AutoGenerateColumns="False" > 
    <DataGrid.Columns> 
     <DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True"/> 
     <DataGridComboBoxColumn Header="Type" ItemsSource="{Binding TypeList}" SelectedItemBinding="{Binding Type}"/> 
     ... 
    </DataGrid.Columns> 
</DataGrid> 
関連する問題