Click here to Skip to main content
15,891,431 members
Articles / Desktop Programming / WPF

How to Embed Arbitrary Content in a WPF Control

Rate me:
Please Sign up or sign in to vote.
4.97/5 (20 votes)
19 Sep 2012Apache5 min read 100.3K   1.7K   32  
Many WPF controls can display arbitrary XAML inside them. How can I do that with my own controls?

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4C67766A-3C87-44F4-A3D9-980FD9B132E4}"
	ProjectSection(SolutionItems) = preProject
		DisplayingContent.htm = DisplayingContent.htm
		License.txt = License.txt
	EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NaiveAttempt", "NaiveAttempt", "{DB0BC5F1-3462-495E-9B79-FF9F21CF7051}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CustomControl", "CustomControl", "{BDF33651-3F45-4C2E-B0C2-4C07B625B52E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuickAndDirtyAttempt", "QuickAndDirtyAttempt", "{F8E2CE41-04A6-49FE-8298-79D1D7A308C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NaiveAttempt", "NaiveAttempt\NaiveAttempt.csproj", "{47A71C4D-BE59-4C56-981A-BBFCB36B406A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickAndDirtyAttempt", "QuickAndDirtyAttempt\QuickAndDirtyAttempt.csproj", "{D5A25200-8159-4D65-BB03-742A5DF3245C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ContentControl", "ContentControl", "{3C203E7E-68B5-4F14-8C96-BEFF2E17BF3C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsingContentControl", "ContentControl\UsingContentControl\UsingContentControl.csproj", "{7401DB06-E4DF-4335-8B1B-04BCD3D54F13}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "img", "img", "{822F8C8F-75A2-4A00-B8A2-2E7C6F251D81}"
	ProjectSection(SolutionItems) = preProject
		img\AddingCustomControl.png = img\AddingCustomControl.png
		img\CustomControlHierarchy.jpg = img\CustomControlHierarchy.jpg
		img\QuickAndDirtyAttempt.png = img\QuickAndDirtyAttempt.png
		img\UsingContentControl.png = img\UsingContentControl.png
	EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyControls", "CustomControl\MyControls\MyControls.csproj", "{DFCFF8BD-60D6-4AA7-88BE-320414BE418F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsingMyControls", "CustomControl\UsingMyControls\UsingMyControls.csproj", "{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{47A71C4D-BE59-4C56-981A-BBFCB36B406A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{47A71C4D-BE59-4C56-981A-BBFCB36B406A}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{47A71C4D-BE59-4C56-981A-BBFCB36B406A}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{47A71C4D-BE59-4C56-981A-BBFCB36B406A}.Release|Any CPU.Build.0 = Release|Any CPU
		{D5A25200-8159-4D65-BB03-742A5DF3245C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{D5A25200-8159-4D65-BB03-742A5DF3245C}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{D5A25200-8159-4D65-BB03-742A5DF3245C}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{D5A25200-8159-4D65-BB03-742A5DF3245C}.Release|Any CPU.Build.0 = Release|Any CPU
		{7401DB06-E4DF-4335-8B1B-04BCD3D54F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{7401DB06-E4DF-4335-8B1B-04BCD3D54F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{7401DB06-E4DF-4335-8B1B-04BCD3D54F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{7401DB06-E4DF-4335-8B1B-04BCD3D54F13}.Release|Any CPU.Build.0 = Release|Any CPU
		{DFCFF8BD-60D6-4AA7-88BE-320414BE418F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{DFCFF8BD-60D6-4AA7-88BE-320414BE418F}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{DFCFF8BD-60D6-4AA7-88BE-320414BE418F}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{DFCFF8BD-60D6-4AA7-88BE-320414BE418F}.Release|Any CPU.Build.0 = Release|Any CPU
		{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(NestedProjects) = preSolution
		{822F8C8F-75A2-4A00-B8A2-2E7C6F251D81} = {4C67766A-3C87-44F4-A3D9-980FD9B132E4}
		{47A71C4D-BE59-4C56-981A-BBFCB36B406A} = {DB0BC5F1-3462-495E-9B79-FF9F21CF7051}
		{DFCFF8BD-60D6-4AA7-88BE-320414BE418F} = {BDF33651-3F45-4C2E-B0C2-4C07B625B52E}
		{A4C28EDA-97A3-482A-9D25-C6E99AA4A7FA} = {BDF33651-3F45-4C2E-B0C2-4C07B625B52E}
		{D5A25200-8159-4D65-BB03-742A5DF3245C} = {F8E2CE41-04A6-49FE-8298-79D1D7A308C2}
		{7401DB06-E4DF-4335-8B1B-04BCD3D54F13} = {3C203E7E-68B5-4F14-8C96-BEFF2E17BF3C}
	EndGlobalSection
EndGlobal

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site: www.ikriv.com.

Comments and Discussions