Quantcast
Viewing all articles
Browse latest Browse all 18858

Resources and ContentControl templates

When setting a contentcontrols template to xaml in code behind I cant access a static resource contained in the parent xaml.

I have a contentcontrol as follows:

<ContentControl x:Name="ccMaterial"><ContentControl.Resources><x:Array x:Key="BondListKey"Type="sys:Int32"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"/></ContentControl.Resources></ContentControl>

then in codebehind I am setting the template as follows:

string template ="<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>"+"<ComboBox Grid.Column=\"1\" Grid.Row=\"0\" ItemsSource=\"{Binding Source={StaticResource BondListKey}}\"  />"+"</ControlTemplate>";
ccMaterial.Template=(ControlTemplate)XamlReader.Parse(template);

The problem is that when i try to run this I get the exception saying that the resource "BondListKey" cannot be found. Can anyone explain why?

Please let me know if you need anymore information.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>