DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Build a Serverless App Fast With Zipper: Write TypeScript, Offload Everything Else
  • MuleSoft: Tactical and Strategical Role of an Application Template
  • Introduction To Template-Based Email Design With Spring Boot
  • The Power of Template-Based Document Generation with NLP and AI in Python

Trending

  • How To Optimize Feature Sets With Genetic Algorithms
  • The Emergence of Cloud-Native Integration Patterns in Modern Enterprises
  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • What Is Good Database Design?

WPF Kid Stuff: Extracting a Control Template

Shafqat Ahmed user avatar by
Shafqat Ahmed
·
Feb. 18, 09 · News
Like (0)
Save
Tweet
Share
10.09K Views

Join the DZone community and get the full member experience.

Join For Free

One of the design principles for WPF was to enable the developer decide the look and feel of the control and that resulted in the most versatile UI framework that can be customized in any way the developer wants. Previously there were many widgets for different languages and frameworks because their look could not be customized beyond the method the control builder provided. With the help of templates in WPF that has changed and that is why there are a lot less custom controls in WPF than the previous technologies. In order to customize something the end developer has to only modify the templates.

If we want to modify a the default look of a controls that is not controllable by the properties, the best way to do that is to extract the existing template of the control and change that. Manually we could open up Expression Blend and right click on a control end edit a copy of the template. See image below.

This would actually reveal the control template that builds control and we can modify it and use as we please.

Another procedure is the extract the template from code is to get the template from the control itself. We can write c# code to extract the template like this …

// Get the template from the control 
ControlTemplate template = ctl.Template;

// We want our xaml of be properly indented, ohterwise
// we would not be able to indent them.
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;

// Make the string builder
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, xmlSettings);
XamlWriter.Save(template, writer);


// Now the sb.ToString() should give us the template

Note: There will be more controls in the xaml template output. Their templates can be extracted further.

 

Windows Presentation Foundation Template

Published at DZone with permission of Shafqat Ahmed. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Build a Serverless App Fast With Zipper: Write TypeScript, Offload Everything Else
  • MuleSoft: Tactical and Strategical Role of an Application Template
  • Introduction To Template-Based Email Design With Spring Boot
  • The Power of Template-Based Document Generation with NLP and AI in Python

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: