c# - Sharing a ListView across multiple TabItems -


I have started working on a project and for the first time I am using WPF. I am typing an XAM and seeing the results of the render and I have had reusability problems again.

I have a tab control with three tabs. Each tab will have a list view, each list view will be identical in the case of layout / structure, but will hold different states of data. It looks like currently:

  & lt; TabControl & gt; & Lt; TabItem header = "green" & gt; & Lt; ListView & gt; & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn Header = "Header 1" width = "100" /> & Lt; GridViewColumn Header = "Header 2" width = "100" /> & Lt; GridViewColumn Header = "Header 3" width = "100" /> & Lt; / GridView & gt; & Lt; /ListView.View> & Lt; / ListView & gt; & Lt; / TabItem & gt; & Lt; TabItem header = "amber" & gt; & Lt; / TabItem & gt; & Lt; TabItem header = "red" & gt; & Lt; / TabItem & gt; & Lt; / TabControl & gt; In amber and red tabs I am unsure that I should just copy and paste that is in a green tab or if there is a better way of doing this, which allows me to reuse the list easily in three places. XAML for  

Edit: After reviewing the answer given by Andy, I have used the following solution with some additional research

  & lt ; Window.Resources & gt; & Lt; GridView x: Shared = "False" x: Key = "BaseListView" & gt; & Lt; GridViewColumn Header = "Header 1" width = "100" /> & Lt; GridViewColumn Header = "Header 2" width = "100" /> & Lt; GridViewColumn Header = "Header 3" width = "100" /> & Lt; GridViewColumn Header = "Header 4" width = "100" /> & Lt; GridViewColumn Header = "Header 5" width = "100" /> & Lt; GridViewColumn Header = "Header 6" width = "100" /> & Lt; GridViewColumn Header = "Header 7" width = "100" /> & Lt; / GridView & gt; & Lt; /Window.Resources> & Lt; DockPanel & gt; & Lt; Toolbartrack dockpanel.doc = "top" & gt; & Lt; Toolbar & gt; & Lt; Button Tooltip = "Upload HSBC Spreadsheet File" & gt; & Lt; Image Source = "/ Resource / Button / Upload Button." "Height =" 32 "width =" 32 "& gt; & lt; / image & gt; & gt; & gt; button & gt; & lt; / toolbar & gt; & gt; / ToolBarTray & gt; & lt; TabControl> TabItem Header = "Green">     View ListView = "{DynamicResource BaseListView}">   TabItem Header = "Red" && Lt; & lt; Gt; & lt; View ListView = "{DynamicResource BaseListView}">     Actual In terms of resource usage, you can not get lists to share a list.    

Common view, but you can style view so that you can only Once it needs to be created.

Keep in mind the X: Shared feature here, this means that a new instance of the scene will be created for each list view. & lt; Window x: orbit = "wpfApplication2.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http: //schemas.microsoft.com/winfx/2006/ Xaml "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Window.Resources & gt; & Lt; Style TargetType = "ListView" x: Shared = "False" & gt; & Lt; Setter Property = "View" & gt; & Lt; Setter.Value & gt; & Lt; GridView & gt; & Lt; GridViewColumn Header = "Header 1" width = "100" /> & Lt; GridViewColumn Header = "Header 2" width = "100" /> & Lt; GridViewColumn Header = "Header 3" width = "100" /> & Lt; / GridView & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; /Window.Resources> & Lt; TabControl & gt; & Lt; TabItem header = "green" & gt; & Lt; ListView & gt; & Lt; / ListView & gt; & Lt; / TabItem & gt; & Lt; TabItem header = "amber" & gt; & Lt; ListView & gt; & Lt; / ListView & gt; & Lt; / TabItem & gt; & Lt; TabItem header = "red" & gt; & Lt; ListView & gt; & Lt; / ListView & gt; & Lt; / TabItem & gt; & Lt; / TabControl & gt; & Lt; / Window & gt;

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -