0

I create many views Now I have a view which has a ListView. The ListView has a toggle button in the header. It can be expanded or collapsed.

<ListView>
 <ListView.View>
      <GridView ColumnHeaderContainerStyle="{StatckResource ListViewHeaders}">
           <GridViewColumn CellTemplate="{StaticResource myCellTemplate}" />
      </GridView>
 </ListView.View>
 <ListView.GroupStyle>
      <GroupStyle>
           <GroupStyle.ContainerStyle>
                 <Style TargetType="{x:Type GroupItem}">
                      <Setter Property="Background" Value="Red" />
                 </Style>
           </GroupStyle.ContainerStyle>
     </GroupStyle>
 </ListView.GroupStyle>
</ListView>  

The question is that the ListViewItems must be the components in other Views. The definition of the component is something like a gridview in other view or a stackpanel in other view or maybe just a button in other view.

When the page is loaded, all ListView items are collapsed. When I click the toggle button(expander), the items should be expanded.

My question is I don't know how to add/insert the components in other views into this ListView. I think that we may find some x:Name something like. But just don't know.

Need code sample.

Bigeyes
  • 1,508
  • 2
  • 23
  • 42
  • I think you should build your components as separate `UserControl`. The fact that components will be *duplicated* will rely on `DataTemplate` and the binding with your ModelView. Can you provide two views and a component that must be in both? – P.Manthe Dec 01 '17 at 02:38
  • @Bob. I don't know. An `UserControl` contains a few components. But for the demo purpose, we could start from one UserControl has only one component then add it to the ListView? – Bigeyes Dec 01 '17 at 02:47
  • I can suggest you to have a look on `UserControl` tutorial or related questions on stackoverflow :D. – P.Manthe Dec 01 '17 at 08:13
  • Well well.......Maybe (https://stackoverflow.com/questions/1400260/wpf-usercontrol-exposing-inner-listitems)[this] one and (https://stackoverflow.com/questions/14279236/how-to-expose-a-dependencyproperty-of-a-control-nested-in-a-usercontrol)[that] one could be helpful. I don't know. – Bigeyes Dec 01 '17 at 12:55

0 Answers0