Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Unity in WPF Custom Controls
    primarykey
    data
    text
    <p>I'm attempting to create a WPF custom control that includes a reference to the unity container that has been created in the BootStrapper - e.g.</p> <p>The reason being that I would like the custom control to be able to resolve the unity container to be able to use some of the services that have been registered to the container. e.g. a user preference service / an entitlements service.</p> <p>So far I have created my custom control and have included in the code behind file the following dependency property</p> <pre><code>public static readonly DependencyProperty ContainerProperty = DependencyProperty.Register("Container", typeof(UnityContainer), typeof(SomeCustomWPFControl), new PropertyMetadata("DefaultTestValue")); public UnityContainer Container { get { return (UnityContainer)GetValue(ContainerProperty); } set { SetValue(ContainerProperty, value); } } </code></pre> <p>In the WPF form where I'm attempting to include my custom control, I've added the following line to the Resources area:</p> <pre><code>&lt;Unity:UnityContainer x:Key="unitContainer"&gt;&lt;/Unity:UnityContainer&gt; </code></pre> <p>In the form it's self I've attempted to create the custom control:</p> <pre><code>&lt;Globe:SomeCustomWPFControl Container="{DynamicResource unitContainer}" DockPanel.Dock="Right" x:Name="JimEditor1" Grid.Column="0" Grid.Row="3"&gt;&lt;/Globe:SomeCustomWPFControl&gt; </code></pre> <p>The only error information I receive at run time is</p> <p>Error at object 'System.Windows.Controls.Grid' in markup file '[assembly name];[path/file].xaml' Line 135 Position 22.</p> <p>Any suggestions as to where I'm going wrong? Thx.</p> <p>Full Xaml:</p> <pre><code>&lt;UserControl x:Class="DB.GPF.Globe.Views.JimTestPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Globe="clr-namespace:DB.GPF.Globe" xmlns:Unity="clr-namespace:Microsoft.Practices.Unity;assembly=Microsoft.Practices.Unity"&gt; &lt;UserControl.Resources&gt; &lt;Unity:UnityContainer x:Key="unitContainer"&gt;&lt;/Unity:UnityContainer&gt; &lt;/UserControl.Resources&gt; &lt;Grid&gt; &lt;Globe:SomeCustomWPFControl Container="{DynamicResource unitContainer}" x:Name="JImTestControl1"&gt;&lt;/Globe:SomeCustomWPFControl&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>Update: The problem appears to be having a DependencyProperty of type UnityContainer or IUnityContainer, if the type is changed to an inbuilt .Net type, e.g. string then it runs fine. Any ideas why we can't have a DependencyProperty of type UnityContainer or IUnityContainer?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload