tags:

views:

1103

answers:

2

Is there a way to reuse a 3rd party control reference?

For example, I have this referenced in my App.xaml

xmlns:cust="clr-namespace:ThirdParty.Controls;assembly=ThirdParty.Controls"

I don't want to repeat this 3rd party control xml namespace on each page/control that needs a control from the library.

Is there anyway to centralize these references and use the prefix defined here? The possibility of each control having a different prefix is also worrisome. In asp.net you would put a reference in the web.config and it was available globally, I'm just looking to see if there is a similar method in WPF.

+1  A: 

Two options I am thinking

1) Wrap that control into a UserControl and then use your UserControl in all the places.

2) Declare the third party control as a Resource somewhere and then use DynamicResource reference to that on your other places.

The second option can be implemented as bellow.

Where ever you want the third party control put a ContentControl like bellow

<ContentControl Template="{DynamicResource thirdPartyControlTemplate}" />

The ControlTemplate will be in the Resource file or at App.Xaml as bellow.

  xmlns:thridParty="clr-namespace:WpfCustomControlLibrary1;assembly=WpfCustomControlLibrary1"                >
<Application.Resources>
    <ControlTemplate x:Key="thirdPartyControlTemplate" TargetType="{x:Type ContentControl}">
        <thridParty:ThirdPartyControl />
    </ControlTemplate>
</Application.Resources>

You can see that the namespace declaration will be always on this resource file and you will be able to use that Control control from any place

Jobi Joy
Thanks, this is the closest I can get to a global include. Though I'll probably just ignore the includes on every window and deal with it.
Jab
A: 

Take an example from the built-in control template for a Label:

<ControlTemplate TargetType="Label" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:s="clr-namespace:System;assembly=mscorlib" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

Show Me The Template is an amazingly helpful resource for these kinds of things. HTH

Bryan Anderson
I'm not sure how this would help. I don't want to change the template of the 3rd party control, I want to reference the same control from a central xmlns import. If this buys me that somehow, please explain in more detail.
Jab
Ah, I misread your question. I thought you had a user or custom control that required a 3rd party library. Really what you're looking for is a way to do a global include in XAML.
Bryan Anderson
Yeah, sad there isn't a solution. It's not an issue doing something in Blend as it does it all for you, but visual studio is lacking.
Jab