WPF应用开发之控件动态内容展示

打印 上一主题 下一主题

主题 840|帖子 840|积分 2520

在我们开发一些复杂信息的时候,由于需要动态展示一些相关信息,因此我们需要考虑一些控件内容的动态展示,可以通过动态构建控件的方式进行显示,如动态选项卡展示不同的信息,或者动态展示一个自定义控件的内容等等,目的就是能够减少一些硬编码的处理方式,以及能够灵活的展示数据。本篇随笔通过实际案例介绍WPF应用开发之控件动态内容展示。
1、选项卡TabControl的动态内容展示

在我们客户关系管理模块中,往往需要展示一个客户相关的很多数据,我们可以把它们放在多个选项卡中进行统一展示,如下界面所示。

由于客户的相关模块信息比较多,因此我们通过选项卡的展示是比较合理的一种界面组织方式,这里由于不同的客户信息,他们展示的内容不同(但结构相同),因此可以考虑动态的刷新选项卡项目TabItem的内容数据进行。
因此我们这里引入一个自定义的控件AllRelatedListControl,用来承载所有需要展示的模块一个组合。
因此在主页面上,我们可以通过一个Divider分隔控件隔开,展示客户相关的数据,如下XAML 代码所示。
  1. <hc:Divider
  2.     Margin="0"
  3.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  4.     LineStrokeThickness="2" />
  5. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  6.    
  7.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  8. </Grid>
复制代码
这个自定义的控件,主要的作用是组合多个选项卡项目,减少主界面的代码,并增加一些共同的属性和方法来控制数据的更新显示的。
  1. <hc:Divider
  2.     Margin="0"
  3.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  4.     LineStrokeThickness="2" />
  5. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  6.    
  7.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  8. </Grid><hc:Divider
  9.     Margin="0"
  10.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  11.     LineStrokeThickness="2" />
  12. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  13.    
  14.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  15. </Grid><hc:Divider
  16.     Margin="0"
  17.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  18.     LineStrokeThickness="2" />
  19. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  20.    
  21.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  22. </Grid><hc:Divider
  23.     Margin="0"
  24.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  25.     LineStrokeThickness="2" />
  26. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  27.    
  28.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  29. </Grid><hc:Divider
  30.     Margin="0"
  31.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  32.     LineStrokeThickness="2" />
  33. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  34.    
  35.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  36. </Grid><hc:Divider
  37.     Margin="0"
  38.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  39.     LineStrokeThickness="2" />
  40. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  41.    
  42.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  43. </Grid><hc:Divider
  44.     Margin="0"
  45.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  46.     LineStrokeThickness="2" />
  47. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  48.    
  49.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  50. </Grid><hc:Divider
  51.     Margin="0"
  52.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  53.     LineStrokeThickness="2" />
  54. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  55.    
  56.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  57. </Grid><hc:Divider
  58.     Margin="0"
  59.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  60.     LineStrokeThickness="2" />
  61. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  62.    
  63.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  64. </Grid><hc:Divider
  65.     Margin="0"
  66.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  67.     LineStrokeThickness="2" />
  68. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  69.    
  70.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  71. </Grid><hc:Divider
  72.     Margin="0"
  73.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  74.     LineStrokeThickness="2" />
  75. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  76.    
  77.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  78. </Grid><hc:Divider
  79.     Margin="0"
  80.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  81.     LineStrokeThickness="2" />
  82. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  83.    
  84.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  85. </Grid><hc:Divider
  86.     Margin="0"
  87.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  88.     LineStrokeThickness="2" />
  89. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  90.    
  91.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  92. </Grid><hc:Divider
  93.     Margin="0"
  94.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  95.     LineStrokeThickness="2" />
  96. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  97.    
  98.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  99. </Grid><hc:Divider
  100.     Margin="0"
  101.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  102.     LineStrokeThickness="2" />
  103. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  104.    
  105.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  106. </Grid><hc:Divider
  107.     Margin="0"
  108.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  109.     LineStrokeThickness="2" />
  110. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  111.    
  112.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  113. </Grid><hc:Divider
  114.     Margin="0"
  115.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  116.     LineStrokeThickness="2" />
  117. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  118.    
  119.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  120. </Grid><hc:Divider
  121.     Margin="0"
  122.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  123.     LineStrokeThickness="2" />
  124. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  125.    
  126.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  127. </Grid><hc:Divider
  128.     Margin="0"
  129.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  130.     LineStrokeThickness="2" />
  131. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  132.    
  133.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  134. </Grid><hc:Divider
  135.     Margin="0"
  136.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  137.     LineStrokeThickness="2" />
  138. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  139.    
  140.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  141. </Grid><hc:Divider
  142.     Margin="0"
  143.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  144.     LineStrokeThickness="2" />
  145. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  146.    
  147.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  148. </Grid><hc:Divider
  149.     Margin="0"
  150.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  151.     LineStrokeThickness="2" />
  152. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  153.    
  154.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  155. </Grid><hc:Divider
  156.     Margin="0"
  157.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  158.     LineStrokeThickness="2" />
  159. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  160.    
  161.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  162. </Grid><hc:Divider
  163.     Margin="0"
  164.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  165.     LineStrokeThickness="2" />
  166. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  167.    
  168.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  169. </Grid><hc:Divider
  170.     Margin="0"
  171.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  172.     LineStrokeThickness="2" />
  173. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  174.    
  175.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  176. </Grid><hc:Divider
  177.     Margin="0"
  178.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  179.     LineStrokeThickness="2" />
  180. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  181.    
  182.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  183. </Grid><hc:Divider
  184.     Margin="0"
  185.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  186.     LineStrokeThickness="2" />
  187. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  188.    
  189.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  190. </Grid><hc:Divider
  191.     Margin="0"
  192.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  193.     LineStrokeThickness="2" />
  194. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  195.    
  196.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  197. </Grid><hc:Divider
  198.     Margin="0"
  199.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  200.     LineStrokeThickness="2" />
  201. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  202.    
  203.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  204. </Grid><hc:Divider
  205.     Margin="0"
  206.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  207.     LineStrokeThickness="2" />
  208. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  209.    
  210.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  211. </Grid><hc:Divider
  212.     Margin="0"
  213.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  214.     LineStrokeThickness="2" />
  215. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  216.    
  217.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  218. </Grid><hc:Divider
  219.     Margin="0"
  220.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  221.     LineStrokeThickness="2" />
  222. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  223.    
  224.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  225. </Grid><hc:Divider
  226.     Margin="0"
  227.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  228.     LineStrokeThickness="2" />
  229. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  230.    
  231.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  232. </Grid><hc:Divider
  233.     Margin="0"
  234.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  235.     LineStrokeThickness="2" />
  236. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  237.    
  238.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  239. </Grid><hc:Divider
  240.     Margin="0"
  241.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  242.     LineStrokeThickness="2" />
  243. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  244.    
  245.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  246. </Grid><hc:Divider
  247.     Margin="0"
  248.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  249.     LineStrokeThickness="2" />
  250. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  251.    
  252.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  253. </Grid><hc:Divider
  254.     Margin="0"
  255.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  256.     LineStrokeThickness="2" />
  257. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  258.    
  259.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  260. </Grid><hc:Divider
  261.     Margin="0"
  262.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  263.     LineStrokeThickness="2" />
  264. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  265.    
  266.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  267. </Grid><hc:Divider
  268.     Margin="0"
  269.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  270.     LineStrokeThickness="2" />
  271. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  272.    
  273.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  274. </Grid><hc:Divider
  275.     Margin="0"
  276.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  277.     LineStrokeThickness="2" />
  278. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  279.    
  280.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  281. </Grid><hc:Divider
  282.     Margin="0"
  283.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  284.     LineStrokeThickness="2" />
  285. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  286.    
  287.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  288. </Grid><hc:Divider
  289.     Margin="0"
  290.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  291.     LineStrokeThickness="2" />
  292. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  293.    
  294.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  295. </Grid><hc:Divider
  296.     Margin="0"
  297.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  298.     LineStrokeThickness="2" />
  299. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  300.    
  301.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  302. </Grid><hc:Divider
  303.     Margin="0"
  304.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  305.     LineStrokeThickness="2" />
  306. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  307.    
  308.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  309. </Grid><hc:Divider
  310.     Margin="0"
  311.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  312.     LineStrokeThickness="2" />
  313. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  314.    
  315.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  316. </Grid><hc:Divider
  317.     Margin="0"
  318.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  319.     LineStrokeThickness="2" />
  320. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  321.    
  322.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  323. </Grid><hc:Divider
  324.     Margin="0"
  325.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  326.     LineStrokeThickness="2" />
  327. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  328.    
  329.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  330. </Grid><hc:Divider
  331.     Margin="0"
  332.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  333.     LineStrokeThickness="2" />
  334. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  335.    
  336.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  337. </Grid><hc:Divider
  338.     Margin="0"
  339.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  340.     LineStrokeThickness="2" />
  341. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  342.    
  343.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  344. </Grid><hc:Divider
  345.     Margin="0"
  346.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  347.     LineStrokeThickness="2" />
  348. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  349.    
  350.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  351. </Grid><hc:Divider
  352.     Margin="0"
  353.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  354.     LineStrokeThickness="2" />
  355. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  356.    
  357.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  358. </Grid><hc:Divider
  359.     Margin="0"
  360.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  361.     LineStrokeThickness="2" />
  362. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  363.    
  364.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  365. </Grid><hc:Divider
  366.     Margin="0"
  367.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  368.     LineStrokeThickness="2" />
  369. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  370.    
  371.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  372. </Grid>     
复制代码
上面的用户控件的界面效果如下所示,它的作用就是组合多个不同的页面。

 和其他自定义控件一样,我们增加一些自定义的属性,如这里是客户的ID,用于赋值后刷新相关的数据的。
  1. <TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>  ///<TabItem Header="客户跟进" Tag="FollowControl">
  4.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  5. </TabItem>    /// 客户ID<TabItem Header="客户跟进" Tag="FollowControl">
  6.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  7. </TabItem>   ///<TabItem Header="客户跟进" Tag="FollowControl">
  8.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  9. </TabItem>    public string?[b] CustomerId[/b]<TabItem Header="客户跟进" Tag="FollowControl">
  10.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  11. </TabItem>   {<hc:Divider
  12.     Margin="0"
  13.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  14.     LineStrokeThickness="2" />
  15. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  16.    
  17.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  18. </Grid> get { return (string?)GetValue(CustomerIdProperty); }<hc:Divider
  19.     Margin="0"
  20.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  21.     LineStrokeThickness="2" />
  22. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  23.    
  24.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  25. </Grid> set { SetValue(CustomerIdProperty, value); }<TabItem Header="客户跟进" Tag="FollowControl">
  26.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  27. </TabItem>   }<TabItem Header="客户跟进" Tag="FollowControl">
  28.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  29. </TabItem>    public static readonly DependencyProperty [b]CustomerIdProperty[/b] = DependencyProperty.Register(<hc:Divider
  30.     Margin="0"
  31.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  32.     LineStrokeThickness="2" />
  33. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  34.    
  35.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  36. </Grid> nameof(CustomerId), typeof(string), typeof(AllRelatedListControl),<hc:Divider
  37.     Margin="0"
  38.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  39.     LineStrokeThickness="2" />
  40. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  41.    
  42.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  43. </Grid> new FrameworkPropertyMetadata("-1", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnCustomerIdPropertyChanged)));<TabItem Header="客户跟进" Tag="FollowControl">
  44.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  45. </TabItem>     private static async void OnCustomerIdPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)<TabItem Header="客户跟进" Tag="FollowControl">
  46.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  47. </TabItem>   {<hc:Divider
  48.     Margin="0"
  49.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  50.     LineStrokeThickness="2" />
  51. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  52.    
  53.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  54. </Grid> if (d is not AllRelatedListControl control)<hc:Divider
  55.     Margin="0"
  56.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  57.     LineStrokeThickness="2" />
  58. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  59.    
  60.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  61. </Grid>     return;<hc:Divider
  62.     Margin="0"
  63.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  64.     LineStrokeThickness="2" />
  65. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  66.    
  67.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  68. </Grid>  if (control != null)<hc:Divider
  69.     Margin="0"
  70.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  71.     LineStrokeThickness="2" />
  72. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  73.    
  74.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  75. </Grid> {<hc:Divider
  76.     Margin="0"
  77.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  78.     LineStrokeThickness="2" />
  79. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  80.    
  81.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  82. </Grid>     var oldValue = (string?)e.OldValue;  // 旧的值<hc:Divider
  83.     Margin="0"
  84.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  85.     LineStrokeThickness="2" />
  86. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  87.    
  88.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  89. </Grid>     var newValue = (string?)e.NewValue; // 更新的新的值<hc:Divider
  90.     Margin="0"
  91.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  92.     LineStrokeThickness="2" />
  93. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  94.    
  95.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  96. </Grid><TabItem Header="客户跟进" Tag="FollowControl">
  97.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  98. </TabItem>//更新数据源<hc:Divider
  99.     Margin="0"
  100.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  101.     LineStrokeThickness="2" />
  102. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  103.    
  104.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  105. </Grid>     await control.InitData(newValue);<hc:Divider
  106.     Margin="0"
  107.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  108.     LineStrokeThickness="2" />
  109. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  110.    
  111.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  112. </Grid> }<TabItem Header="客户跟进" Tag="FollowControl">
  113.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  114. </TabItem>   }
复制代码
而我们每个子控件里面,其实也是已经根据父控件的客户ID进行了绑定属性了,如下所示。
  1. <TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>
复制代码
如果我们要根据数据库的配置信息,用来判断哪个选项卡显示或者隐藏,那么可以进一步进行处理每个TabItem的Visibility即可
  1. //判断是否显示 foreach (TabItem item in this.tabControl.Items) {     if (!item.Tag.IsEmpty())     {<TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>   item.Visibility = [b]CustomerTabItems.Contains(item.Tag.ToString()!)[/b] ? Visibility.Visible : Visibility.Collapsed;     } }
复制代码
在DataGrid的鼠标键按下左键的时候,我们刷新对应自定义控件的属性CustomerId,就可以刷新相关的客户数据了。
  1.     ///<TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>/// 选中每个客户记录的时候,触发更新客户相关信息     ///<TabItem Header="客户跟进" Tag="FollowControl">
  4.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  5. </TabItem>private async void grid_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)     {<TabItem Header="客户跟进" Tag="FollowControl">
  6.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  7. </TabItem>   if (this.grid.SelectedItem is CustomerInfo selectItem)<TabItem Header="客户跟进" Tag="FollowControl">
  8.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  9. </TabItem>   {<hc:Divider
  10.     Margin="0"
  11.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  12.     LineStrokeThickness="2" />
  13. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  14.    
  15.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  16. </Grid> [b]allRelatedList.CustomerId [/b][b]= selectItem.Id;<hc:Divider
  17.     Margin="0"
  18.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  19.     LineStrokeThickness="2" />
  20. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  21.    
  22.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  23. </Grid>[/b][b] await[/b][b] allRelatedList.InitData(selectItem.Id);[/b]<TabItem Header="客户跟进" Tag="FollowControl">
  24.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  25. </TabItem>   }     }
复制代码
以上就是对于复杂的客户信息内容,使用选项卡动态组合的方式,实现内容的动态展示处理操作。
 
2、动态自定义表单内容的展示

有时候,我们在工作流表单中,需要展示一些固定的申请单信息,以及根据不同流程的表单数据(结构也不同)进行展示,如工作流中,不同的表单数据结构是不同的。

 明细展示效果如下所示。

或者

可以看出不同的流程类型表单,它们的表单结构是不同的,如果我们在一个固定的页面里面展示数据,那么这块表单的数据展示,就需要用到动态控件的展示方式。
我们采用Grid布局排版方式,grid.row=0为固定表单(这里不再赘述),grid.row=1为动态表单内容,如下所示。
  1. <TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>   
复制代码
其中里面 就是我们根据实际表单的内容进行动态展示的地方。
  1. ///  /// 该事件在loaded之后执行,也是在所有元素渲染结束之后执行 ///  ///  protected override async void OnContentRendered(EventArgs e) {     base.OnContentRendered(e);<TabItem Header="客户跟进" Tag="FollowControl">
  2.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  3. </TabItem>//动态构建表单内容展示 formContent     var formId = this.ViewModel.Item.FormId;     if(!formId.IsNullOrEmpty())     {<TabItem Header="客户跟进" Tag="FollowControl">
  4.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  5. </TabItem>   var formInfo = await BLLFactory.Instance.GetAsync(formId);<TabItem Header="客户跟进" Tag="FollowControl">
  6.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  7. </TabItem>   if(formInfo != null && !formInfo.ApplyWpfview.IsNullOrEmpty())<TabItem Header="客户跟进" Tag="FollowControl">
  8.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  9. </TabItem>   {<hc:Divider
  10.     Margin="0"
  11.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  12.     LineStrokeThickness="2" />
  13. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  14.    
  15.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  16. </Grid> var control = ReflectionUtil.CreateInstance([b]formInfo.ApplyWpfview[/b]);<hc:Divider
  17.     Margin="0"
  18.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  19.     LineStrokeThickness="2" />
  20. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  21.    
  22.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  23. </Grid> var data = control as IApplyInit;<hc:Divider
  24.     Margin="0"
  25.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  26.     LineStrokeThickness="2" />
  27. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  28.    
  29.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  30. </Grid> if(data != null)<hc:Divider
  31.     Margin="0"
  32.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  33.     LineStrokeThickness="2" />
  34. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  35.    
  36.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  37. </Grid> {<hc:Divider
  38.     Margin="0"
  39.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  40.     LineStrokeThickness="2" />
  41. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  42.    
  43.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  44. </Grid>     await data.InitData(this.ViewModel.Item.Id);<hc:Divider
  45.     Margin="0"
  46.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  47.     LineStrokeThickness="2" />
  48. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  49.    
  50.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  51. </Grid> }<hc:Divider
  52.     Margin="0"
  53.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  54.     LineStrokeThickness="2" />
  55. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  56.    
  57.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  58. </Grid> formContent.Content = control;<TabItem Header="客户跟进" Tag="FollowControl">
  59.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  60. </TabItem>   }     }<TabItem Header="客户跟进" Tag="FollowControl">
  61.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  62. </TabItem>//初始化工具栏     await InitToolBar(); }
复制代码
我们根据表单ID获取对应的formInfo.ApplyWpfview 属性配置,他就是一个具体的控件的名称路径,因此我们根据这个来进行反射构建一个实例,并把它转换为 IApplyInit 的接口实例,进行调用控件初始化即可。
生成的控件当做Frame控件的Content,从而实现动态内容的展示了。
我们以第一个表单【故障维修】的自定义控件定义来看看
  1. public partial class MaintenanceViewControl : INavigableView<MaintenanceEditViewModel>, <strong>IApplyInit</strong>
复制代码
它实现了 IApplyInit 接口,因此我们可以在动态控件的时候,把它转换为接口实例进行调用,这也是我们约束动态控件实例的一个规则。
不同的控件,他们的数据模型肯定不同,因此由它们自己本身实现具体的获取数据即可。
  1. /// <summary>
  2. /// 初始化相关业务表单数据
  3. /// </summary>
  4. /// <param name="applyId">申请单Id</param>
  5. /// <returns></returns>
  6. public async Task InitData(string applyId)
  7. {
  8.     <strong>this.ViewModel.Item = await BLLFactory<IMaintenanceService>.Instance.FindByApplyId(applyId);
  9.     </strong>this.ViewModel.NotifyChanged();
  10. }
复制代码
这样我们自定义控件的XAML就可以顺利绑定对应的数据展示了,这些控件的内容,可以根据数据库接口,使用我们的代码生成工具进行快速生成,然后进行一定的裁剪调整即可,不必要一个个来编写代码。
  1. <hc:Divider
  2.     Margin="0"
  3.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  4.     LineStrokeThickness="2" />
  5. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  6.    
  7.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  8. </Grid><hc:Divider
  9.     Margin="0"
  10.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  11.     LineStrokeThickness="2" />
  12. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  13.    
  14.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  15. </Grid><hc:Divider
  16.     Margin="0"
  17.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  18.     LineStrokeThickness="2" />
  19. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  20.    
  21.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  22. </Grid><hc:Divider
  23.     Margin="0"
  24.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  25.     LineStrokeThickness="2" />
  26. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  27.    
  28.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  29. </Grid><hc:Divider
  30.     Margin="0"
  31.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  32.     LineStrokeThickness="2" />
  33. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  34.    
  35.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  36. </Grid><hc:Divider
  37.     Margin="0"
  38.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  39.     LineStrokeThickness="2" />
  40. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  41.    
  42.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  43. </Grid><hc:Divider
  44.     Margin="0"
  45.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  46.     LineStrokeThickness="2" />
  47. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  48.    
  49.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  50. </Grid><hc:Divider
  51.     Margin="0"
  52.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  53.     LineStrokeThickness="2" />
  54. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  55.    
  56.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  57. </Grid><hc:Divider
  58.     Margin="0"
  59.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  60.     LineStrokeThickness="2" />
  61. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  62.    
  63.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  64. </Grid><hc:Divider
  65.     Margin="0"
  66.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  67.     LineStrokeThickness="2" />
  68. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  69.    
  70.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  71. </Grid><hc:Divider
  72.     Margin="0"
  73.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  74.     LineStrokeThickness="2" />
  75. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  76.    
  77.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  78. </Grid><hc:Divider
  79.     Margin="0"
  80.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  81.     LineStrokeThickness="2" />
  82. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  83.    
  84.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  85. </Grid><hc:Divider
  86.     Margin="0"
  87.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  88.     LineStrokeThickness="2" />
  89. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  90.    
  91.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  92. </Grid><hc:Divider
  93.     Margin="0"
  94.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  95.     LineStrokeThickness="2" />
  96. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  97.    
  98.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  99. </Grid><hc:Divider
  100.     Margin="0"
  101.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  102.     LineStrokeThickness="2" />
  103. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  104.    
  105.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  106. </Grid><hc:Divider
  107.     Margin="0"
  108.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  109.     LineStrokeThickness="2" />
  110. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  111.    
  112.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  113. </Grid><hc:Divider
  114.     Margin="0"
  115.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  116.     LineStrokeThickness="2" />
  117. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  118.    
  119.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  120. </Grid><hc:Divider
  121.     Margin="0"
  122.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  123.     LineStrokeThickness="2" />
  124. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  125.    
  126.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  127. </Grid><hc:Divider
  128.     Margin="0"
  129.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  130.     LineStrokeThickness="2" />
  131. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  132.    
  133.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  134. </Grid><hc:Divider
  135.     Margin="0"
  136.     LineStroke="{DynamicResource DarkPrimaryBrush}"
  137.     LineStrokeThickness="2" />
  138. <Grid Margin="0,5,0,0" Background="{DynamicResource BackgroundBrush}">
  139.    
  140.     <local:AllRelatedListControl x:Name="allRelatedList" CustomerId="{Binding SelectedItem.Id, ElementName=grid}" />
  141. </Grid><TabItem Header="客户跟进" Tag="FollowControl">
  142.     <local:FollowListControl <strong>CustomerId</strong>="{Binding <strong>CustomerId</strong>, ElementName=allList}" />
  143. </TabItem>  
复制代码
可以看到这部分的代码,和我们生成的编辑界面的内容是相似的,只是进行了适量的裁剪处理,以及增加一些自定义控件,统一界面效果(如附件控件的展示)。
 
以上就是两种不同方式,动态构建不同的内容展示的处理,动态内容可以带来很好的处理便利,不过也不要滥用,比较反射太多还是会牺牲一些UI的性能,不过总体来说肯定是值得的,而且这也是一种UI的处理模式。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

徐锦洪

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表