Problem with XAMLReader

BitSmithy 1,911 Reputation points


I have a xaml file in my Assets folder "MainPage1.xaml" defined as below.

    <Grid local:PageControl.PageHeight="10">

Next, I am trying to load this file to my app using XAMLReader

private async void Page_Loaded(object sender, RoutedEventArgs e) 
	var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");             
	string xamlDefinition = await Windows.Storage.FileIO.ReadTextAsync(await folder.GetFileAsync("MainPage1.xaml"));           
	var xamlElement = ((FrameworkElement)XamlReader.Load(xamlDefinition)); 

I get such error:


The attachable property 'PageHeight' was not found in type 'PageControl'. [Line: 5 Position: 11]”

PageControl class is defined as below:

public class PageControl : DependencyObject 
public static readonly DependencyProperty PageHeightProperty =     DependencyProperty.RegisterAttached(         "PageHeight",
        new PropertyMetadata(default(double))

        public static void SetPageHeight(UIElement element, double value)
            element.SetValue(PageHeightProperty, value);

        public static double GetPageHeight(UIElement element)
            return (double)element.GetValue(PageHeightProperty);         	
}//END PageControl 

I did some tests and behavior of this issue is strange:
If, I move the code to newly created app this code works.
In previous version of my app this code was working.
In debug mode it works, in release mode it doesnt work.

My app is too big to share it, so please guess where problem can lies.
Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 15,911 Reputation points Microsoft Vendor

    Hi @BitSmithy ,

    1>C:\Users......\Properties\Default.rd.xml(29): warning : ILTransform: warrning ILT0027: Property Element „PageHeight” can't be found in „MyNamespace.PageControl” element. 1>C:\Users.......\Properties\Default.rd.xml(30): warning : ILTransform: warrning ILT0027: Property Eleemnt „PageHeightProperty” can't be found in „MyNamespace.PageControl” element.

    Here is the workaround, use local:PageControl.PageHeight first in MainPage.xaml or other non-XamlReader.loaded object.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful