1024programmer Asp.Net Dynamic content display of controls in WPF application development

Dynamic content display of controls in WPF application development

Dynamic content display of controls in WPF application development

When we develop some complex information, we need to dynamically display some relevant information, so we need to consider the dynamic display of some control contents, which can be displayed by dynamically building controls, such as dynamic tabs to display different information, or dynamic display The content of a custom control, etc., is intended to reduce some hard-coded processing methods and display data flexibly. This essay introduces the dynamic content display of controls in WPF application development through actual cases.

When we develop some complex information, we need to dynamically display some relevant information, so we need to consider the dynamic display of some control contents, which can be displayed by dynamically building controls, such as dynamic tabs to display different information. Or dynamically display the content of a custom control, etc. The purpose is to reduce some hard-coded processing methods and display data flexibly. This essay introduces the dynamic content display of controls in WPF application development through actual cases.

1. Dynamic content display of tab TabControl

In our customer relationship management module, we often need to display a lot of data related to a customer. We can put them in multiple tabs for unified display, as shown in the following interface.

Since there is a lot of information about customers’ related modules, our display through tabs is a more reasonable way to organize the interface. Due to different customer information, the content displayed here is different (but the structure is the same), so it can be considered Dynamically refresh the content data of the tab item TabItem.

So we introduce a custom control AllRelatedListControl here to host a combination of all modules that need to be displayed.

So on the main page, we can display customer-related data separated by a Divider control, as shown in the following XAML code.

<hc:Divider
     Margin="0  "
     LineStroke="{  DynamicResource DarkPrimaryBrush}"
     LineStrokeThickness="2" />
 <Grid Margin="0,5,0,0  " Background="  {DynamicResource BackgroundBrush}  ">
     <!-- Customer related data-->
     <local:AllRelatedListControl   x:Name="allRelatedList" CustomerId="  span>{Binding SelectedItem.Id, ElementName=grid}" />
 </Grid>

The main function of this custom control is to combine multiple tab items, reduce the code of the main interface, and add some common properties and methods to control the update and display of data.

<UserControl
     x:Class=  "WHC.SugarProject.CRM.WpfUI.Views.Pages.AllRelatedListControl"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:local="clr-namespace:WHC.SugarProject.CRM.WpfUI.Views.Pages"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     x:Name="allList"
     d:DesignHeight="450"
     d:DesignWidth="800"
     Background="{  DynamicResource RegionBrush}"
     mc:Ignorable="d">
     <Grid>
         <!-- Customer related data-->
         <TabControl
             x:Name=  "tabControl"
             Height="auto"
             HorizontalAlignment="Left"
             HorizontalContentAlignment="Left"
             Background="LightCyan"
             Style="{  StaticResource TabControlCapsuleSolid}"
             TabStripPlacement="Top">
             <TabItem Header="Customer follow-up" Tag="FollowControl">
                 <local:FollowListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Contact information" Tag="ContactControl">
                 <local:ContactListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Customer visit"   Tag="VisitControl">
                 <local:VisitListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Sales Opportunity"   Tag="ChanceControl">
                 <local:ChanceListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Customer Document"   Tag="FileDataControl">
                 <local:FileDataListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Contract Document"   Tag="ContractControl">
                 <local:ContractListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Product Quotation"   Tag="QuotationControl">
                 <local:QuotationListControl   CustomerId="{Binding CustomerId, ElementName=allList}"   />
             </TabItem>
             <TabItem Header="Customer call"   Tag<span stx:Name=  "txtRepairFee"
                 Margin="5"
                 hc:TitleElement.Title="Estimated maintenance cost"
                 hc:TitleElement.TitlePlacement="Left"
                 IsReadOnly="True"
                 Text="{  Binding ViewModel.Item.RepairFee}" />
         </hc:Col>
         <hc:Col   Span="12" />
     </hc:Row>

     <hc:Row  >
         <hc:Col   Span="24">
             <TextBox
                 x:Name=  "txtNote"
                 Height="50"
                 Margin="5"
                 VerticalAlignment="Top"
                 VerticalContentAlignment="Top"
                 hc:TitleElement.Title="Remarks"
                 hc:TitleElement.TitlePlacement="Left"
                 AcceptsReturn="True"
                 IsReadOnly="True"
                 Text="{  Binding ViewModel.Item.Note}" />
         </hc:Col>
     </hc:Row>
     <hc:Row  >
         <hc:Col  >
             <control:AttachmentControl   AttachmentGUID="{Binding ViewModel.Item.AttachGUID}"   Text="Related  Attachment" />
         </hc:Col>
     </hc:Row>
 </StackPanel>

You can see that this part of the code is similar to the content of the editing interface we generated, except that it has been appropriately cropped and added some custom controls to unify the interface effect (such as the display of attachment controls).

The above are two different ways to dynamically construct different content display processing. Dynamic content can bring great processing convenience, but do not abuse it. Too much reflection will still sacrifice some UI performance, but overall It is definitely worth it, and this is also a UI processing mode.



Focus on code generation tools, .Net/.NetCore framework architecture and software development, as well as various Vue.js front-end technology applications. He is the author of Winform development framework/hybrid development framework, WeChat development framework, Bootstrap development framework, ABP development framework, SqlSugar development framework and other framework products.

Please indicate the source for reprinting: Writer: Wu Huacong http://www.iqidi.com
gba(0, 0, 255, 1)”></hc:Row>
</StackPanel>

You can see that this part of the code is similar to the content of the editing interface we generated, except that it has been appropriately cropped and added some custom controls to unify the interface effect (such as the display of attachment controls).

The above are two different ways to dynamically construct different content display processing. Dynamic content can bring great processing convenience, but do not abuse it. Too much reflection will still sacrifice some UI performance, but overall It is definitely worth it, and this is also a UI processing mode.



Focus on code generation tools, .Net/.NetCore framework architecture and software development, as well as various Vue.js front-end technology applications. He is the author of Winform development framework/hybrid development framework, WeChat development framework, Bootstrap development framework, ABP development framework, SqlSugar development framework and other framework products.

Please indicate the source for reprinting: Writer: Wu Huacong http://www.iqidi.com

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/811179

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索