473,795 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to include XAML files into another XAML file?

Hi, Is it possible to include a XAML file into another XAML file?

For example If i have
- Window1.xaml
- Window2.xaml

and both have a treeview with a custom Style, can i describe the style
in a trvStyle.xaml and then include it in both windows?

Thanks in advance
Jun 27 '08 #1
6 10118
On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
Hi, Is it possible to include a XAML file into another XAML file?

For example If i have
- Window1.xaml
- Window2.xaml

and both have a treeview with a custom Style, can i describe the style
in a trvStyle.xaml and then include it in both windows?

Thanks in advance
I don't know of anyway to do that (that doesn't mean there isn't :)-
but If this is the same application, you could define the style
in the application resources, and then it will be available globablly.

--
Tom Shelton
Jun 27 '08 #2
Tom Shelton wrote:
On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
>Hi, Is it possible to include a XAML file into another XAML file?

For example If i have
- Window1.xaml
- Window2.xaml

and both have a treeview with a custom Style, can i describe the style
in a trvStyle.xaml and then include it in both windows?

Thanks in advance

I don't know of anyway to do that (that doesn't mean there isn't :)-
but If this is the same application, you could define the style
in the application resources, and then it will be available globablly.
And what if i want to create a control in XAML and then reuse it in
another window?

And to be more precise, I'm loading XAML on the fly, so I'd not want to
load it as a resource. However thanks for your reply :)
Jun 27 '08 #3
On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
Tom Shelton wrote:
>On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
>>Hi, Is it possible to include a XAML file into another XAML file?

For example If i have
- Window1.xaml
- Window2.xaml

and both have a treeview with a custom Style, can i describe the style
in a trvStyle.xaml and then include it in both windows?

Thanks in advance

I don't know of anyway to do that (that doesn't mean there isn't :)-
but If this is the same application, you could define the style
in the application resources, and then it will be available globablly.

And what if i want to create a control in XAML and then reuse it in
another window?

And to be more precise, I'm loading XAML on the fly, so I'd not want to
load it as a resource. However thanks for your reply :)
If your loading it on the fly, then you would have to use some procedural
code, and do something like this...

Create the trvStyle.xaml:
<ResourceDictio nary
xmlns="http://......"
xmlns:x="http://...." >
<Style x:Key="TreeView Style" TargetType="{x: Type TreeView}">
<!-- do your style stuff here -->
</Style>
</ResourceDiction ary>

<Window x:Name="Window1 " ...>
....
<TreeView Style="{Dynamic Resource TreeViewStyle}" >
...
</TreeView>
</Window>

Then you need to load the style dynamically (XamlReader.Loa d) the resource
dictionary and then either replace the Application.Cur rent.Resources (or what
ever ResourceDiction ary your interested in) or you could merge them together.
Adding or replacing the enteries with those from the dynamically loaded
dictionary.

HTH

--
Tom Shelton
Jun 27 '08 #4
Tom Shelton wrote:
On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
>Tom Shelton wrote:
>>On 2008-06-06, star-italia <st*********@co mmunity.nospamw rote:
Hi, Is it possible to include a XAML file into another XAML file?

For example If i have
- Window1.xaml
- Window2.xaml

and both have a treeview with a custom Style, can i describe the style
in a trvStyle.xaml and then include it in both windows?

Thanks in advance
I don't know of anyway to do that (that doesn't mean there isn't :)-
but If this is the same application, you could define the style
in the application resources, and then it will be available globablly.
And what if i want to create a control in XAML and then reuse it in
another window?

And to be more precise, I'm loading XAML on the fly, so I'd not want to
load it as a resource. However thanks for your reply :)

If your loading it on the fly, then you would have to use some procedural
code, and do something like this...

Create the trvStyle.xaml:
<ResourceDictio nary
xmlns="http://......"
xmlns:x="http://...." >
<Style x:Key="TreeView Style" TargetType="{x: Type TreeView}">
<!-- do your style stuff here -->
</Style>
</ResourceDiction ary>

<Window x:Name="Window1 " ...>
...
<TreeView Style="{Dynamic Resource TreeViewStyle}" >
...
</TreeView>
</Window>

Then you need to load the style dynamically (XamlReader.Loa d) the resource
dictionary and then either replace the Application.Cur rent.Resources (or what
ever ResourceDiction ary your interested in) or you could merge them together.
Adding or replacing the enteries with those from the dynamically loaded
dictionary.

HTH
Thank you for your help
Jun 27 '08 #5
Hello star-italia and Tom,

XamlReader.Load () can do the task when the resource dictionary is in a
loose XAML form. However, if the resource dictionary is compiled into
BAML, we need to use the Application.Loa dComponent() method to de-serialize
it into ResourceDiction ary object, then add it to either
Application.Cur rent.Resources or Window.Resource s dictionary through the
MergedDictionar ies property:

ResourceDiction ary resourceDiction ary = Application.Loa dComponent(new
Uri("CommonReso urces.xaml", UriKind.Relativ e)) as ResourceDiction ary;
if (resourceDictio nary != null)
{

Application.Cur rent.Resources. MergedDictionar ies.Add(resourc eDictionary);
}

When the resource is merged into the Application level, we use
StaticResource or DynamicResource to refer to them in either Window1.xaml
or Widnow2.xaml files.
The code above can also be written in Window1 or Window2 constructor at
codebehind as follows:
ResourceDiction ary resourceDiction ary = Application.Loa dComponent(new
Uri("CommonReso urces.xaml", UriKind.Relativ e)) as ResourceDiction ary;
if (resourceDictio nary != null)
{
this.Resources. MergedDictionar ies.Add(resourc eDictionary);
}
In this way, the window will have a separate copy of the resource
dictionaries, though this might not be very efficient considering the
consumption of the memory.

If you plan to merge resources completely in XAML, we can directly specify
the MergedDictionar y in XAML as follows:
<App.Resource s>
<ResourceDictio nary>
<ResourceDictio nary.MergedDict ionaries>
<ResourceDictio nary Source="pack uri to the resource dictionary xaml
file"/>
</ResourceDiction ary.MergedDicti onaries
</ResourceDiction ary>
</ App.Resources>
One caveat here is that you define the Visuals like Button in the resource
dictionary as follows:
<Button x:Key="button"/>
Because one Visual can have only one visual parent, we cannot re-parented
it for multiple times in the visual tree, so that if the "button" resource
is going to be reused in multiple places, please specify the x:Shared
property to "False" when declaring the Button resource as this:
<Button x:Shared="False " x:key="button"/>
x:Shared means that, every time this "button" resource is applied, WPF will
create a unique copy. But when x:Shared is specified, resource dictionary
should be compiled into BAML beforehand. So if you are using loose,
non-compiled XAML, please ignore my suggestion.

Regards,
Jialiang Ge (ji****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #6
Hi Star-italia,

How about the problem now?

If you have any question, please feel free to let us now.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
16974
by: Blah Blah | last post by:
here's my problem - i run a web site with a java servlet backend (apache/tomcat/linux/mysql), and i want to add some php content to my jsp pages. why would i want to do something like this? i want to add some third party blogging software that's written in php. it would be easy to have two entirely different sets of pages - but i don't want a MacDLT solution. i'd like to be able to have blog content throughout the website. is there...
11
285
by: Ioannis Vranos | last post by:
Will XAML be mandatory in VS "Orcas"? -- Ioannis Vranos
4
2664
by: Thilaka | last post by:
Hi guys, Recently i read some articles on Longhorn & XAML. & From what i learnt the future for developing UIs lies in XAML. Does this mean that I've got to learn XAML as developing UIs for web or win applications will be different? Or will future versions of VS.Net wrap up the XAML hence making it unnecessary for me to know or learn XAML? --
9
3843
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
6
5770
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
0
5726
by: =?Utf-8?B?WmlnZ3lTaG9ydA==?= | last post by:
I have a sample XAML file: <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Button Name="button2" Height="23" Width="300" Margin="31,37,0,0" Click="doit">Hello World</Button> </StackPanel> If I compile the application normally, the XAML is converted to a .cs and then an application is built: on clicking the button "doit" gets called if it is code-behind or is embedded in an <x:codeblock within the XAML...
2
3276
by: unclepony | last post by:
I just want to make application like a Expression blend but it is not easy for me. And I already know that we can make custom form designer control that behave like visual studio. Microsoft provides a good example how to make custom form designer but I am not sure if I make application with this way , I could generate XAML files with API that Microsoft provides. If you guys have to make application like Microsoft Expression Blend, How...
6
4158
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would try my own small program. The problem is, I seem to be having trouble with memory, i.e. sometimes my program will work and display the correct output, and sometimes it will not and display garbage (in a printf call) so i assume i have been using...
4
17943
by: moondaddy | last post by:
I have a user control located in the following path: projectFolder/PropertyControls/myControl.xaml and in myControl.xaml I have a reference to a resource dictionary like this: <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.