简体   繁体   中英

How do i bind a ListViewItem to Grid?

How do i bind a grid to ListViewItem's content in Listview datatemplate, Like this:

<ListView ItemsSource="{Binding AListInMyViewModel}">
    <ListView.View>
      <GridView >
        <GridViewColumn Header="VariableDetails" Width="10">
          <GridViewColumn.CellTemplate>
            <DataTemplate >
               <ContentPresenter Content="{Binding DetailPanel,UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding}" />
               </DataTemplate>
            </GridViewColumn.CellTemplate>
         </GridViewColumn>
      </GridView>
   </ListView.View>
</ListView>

and in my ViewModel i have the AListInMyViewModel that its every item has a property like this:

Panel DetailPanel{
  get
    {
       Grid MyGrid=new Grid();

       ...
       return MyGrid;
    }

now i want to show the specified grid (DetailPanel) in a cell of the MyListView.

Try specifying that your Panel is public . Also, how have you declared your list? I'm not sure about the way you've set your DataContext in the XAML -- I've never done it that way before. Just to eliminate that as a potential issue, try setting the DataContext to your viewmodel in code-behind. Also, remember to look at your output window after you start your application to see where you could have problems with your databinding, and add these messages to your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM