I am attempting to create my first UserControl and I am getting an error when I view my page in the browser. The error I get is "ag_e_parser_bad_property_value"
When I use the UserControl.xaml outside of a user control, it works fine, but when I try to put my user control into my test page and test xaml, I get the error. Here are the two XAML files I am using and I am curious if you guys could spot what I am doing
wrong.
And here is my test XAML when I am trying to use the user control:
<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="Marquee.UserControl;assembly=ClientBin/Marquee.dll"
Width="640"
Height="480"
Background="Gray"
xmlns:MarqueeUserControl="clr-namespace:Whoiskb;assembly=ClientBin/UserControl.dll"
>
<MarqueeUserControl:Marquee x:Name="marquee1"
Text="This is some sample test to see if the namespace works"
Canvas.Top="100" Canvas.Left="20" />
</Canvas>
Properties you created yourself in the usercontrol class (like the Text property you use in the XAML testpage) can not be assigned in XAML yet:
I have to disagree with you, here, balla. If the property has been created in the UserControl's code-behind, you should be able to access it via the XAML. I have done this quite a bit and if you look at the SilverlightUIControls, it's done quite often
there as well.
Sorry guys, I should have followed up on this post. I did have a Text property in the managed class. The problem had to do with me trying to do too much in the constructor of the managed class. I was trying to modify parts of the control in the constructor
and it appears that the XAML has not been fully loaded yet.
Properties you created yourself in the usercontrol class (like the Text property you use in the XAML testpage) can not be assigned in XAML yet:
I have to disagree with you, here, balla. If the property has been created in the UserControl's code-behind, you should be able to access it via the XAML. I have done this quite a bit and if you look at the SilverlightUIControls, it's done quite often
there as well.
It's very strange that you say this. I also studied the SilverlightUIControls application and it is written in the inline comments (in the code files) that the attributes are initialised at runtime since it is not yet possible to do this in XAML. Maybe I
understood it wrong or it has changed since then? This confuses me...
OK. Let me backpedal a little. I referenced the wrong library. I should have referenced Dave Relyea's layout framework that includes a Grid, StackPanel, Label, TextBox, etc....
All of the objects in this framework have properties named "GridColumn" and "GridRow" which are inherited from the base controls of the library. These properties can be set in your XAML as well as the IsHorizontal property of the StackPanel, Text property
of the Label, etc... which are all custom properties defined in the code-behind of the control. Now, what I have noticed is that I can't set values to custom properties in XAML if the type of the property is that of a custom enum. I believe we come across
this quite a bit in the SDK with the scrollbars.
whoiskb
Member
8 Points
8 Posts
First take on a UserControl
Sep 06, 2007 04:56 AM | LINK
I am attempting to create my first UserControl and I am getting an error when I view my page in the browser. The error I get is "ag_e_parser_bad_property_value"
When I use the UserControl.xaml outside of a user control, it works fine, but when I try to put my user control into my test page and test xaml, I get the error. Here are the two XAML files I am using and I am curious if you guys could spot what I am doing wrong.
UserControl.xaml:
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="parentCanvas"
Width="400"
Height="40"
Background="Yellow"
>
<Canvas.Resources>
<Storyboard x:Name="marqueeStoryBoard">
<DoubleAnimation x:Name="marqueeAnimation" By="1" From="0" Duration="00:00:10" RepeatBehavior="Forever" Storyboard.TargetName="marqueeTextBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" />
</Storyboard>
</Canvas.Resources>
<TextBlock x:Name="marqueeTextBlock" Height="40" Width="400" RenderTransformOrigin="0.5,0.5" FontSize="20" FontWeight="Bold" Text="This is some sample text" >
<TextBlock.RenderTransform>
<TransformGroup>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Canvas>
And here is my test XAML when I am trying to use the user control:
<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="Marquee.UserControl;assembly=ClientBin/Marquee.dll"
Width="640"
Height="480"
Background="Gray"
xmlns:MarqueeUserControl="clr-namespace:Whoiskb;assembly=ClientBin/UserControl.dll"
>
<MarqueeUserControl:Marquee x:Name="marquee1"
Text="This is some sample test to see if the namespace works"
Canvas.Top="100" Canvas.Left="20" />
</Canvas>
thierry.bouq...
Contributor
2054 Points
280 Posts
Re: First take on a UserControl
Sep 26, 2007 09:25 AM | LINK
You are accessing Text property on your MarqueeUserControl.
You should provide a Text property in your managed class otherwise the runtime cannot guess what it should do with this attribute
Ucaya
http://www.ucaya.com
balla
Member
674 Points
200 Posts
Re: First take on a UserControl
Sep 26, 2007 10:16 AM | LINK
Hi whoiskb,
Properties you created yourself in the usercontrol class (like the Text property you use in the XAML testpage) can not be assigned in XAML yet:
<MarqueeUserControl:Marquee x:Name="marquee1" Text="This is some sample test to see if the namespace works" Canvas.Top="100" Canvas.Left="20" />
You must set the Text property from your code-behind (.cs) file.
jasonxz
Participant
1787 Points
557 Posts
Re: First take on a UserControl
Sep 26, 2007 02:02 PM | LINK
I have to disagree with you, here, balla. If the property has been created in the UserControl's code-behind, you should be able to access it via the XAML. I have done this quite a bit and if you look at the SilverlightUIControls, it's done quite often there as well.
Epsilone3
Member
248 Points
138 Posts
Re: Re: First take on a UserControl
Sep 26, 2007 11:07 PM | LINK
In code behind ,You means if the UserControl writing in csharp ? and not in XAML ?
http://epsilone3.spaces.live.com/
whoiskb
Member
8 Points
8 Posts
Re: First take on a UserControl
Sep 26, 2007 11:14 PM | LINK
Sorry guys, I should have followed up on this post. I did have a Text property in the managed class. The problem had to do with me trying to do too much in the constructor of the managed class. I was trying to modify parts of the control in the constructor and it appears that the XAML has not been fully loaded yet.
balla
Member
674 Points
200 Posts
Re: First take on a UserControl
Sep 27, 2007 05:44 AM | LINK
It's very strange that you say this. I also studied the SilverlightUIControls application and it is written in the inline comments (in the code files) that the attributes are initialised at runtime since it is not yet possible to do this in XAML. Maybe I understood it wrong or it has changed since then? This confuses me...
jasonxz
Participant
1787 Points
557 Posts
Re: First take on a UserControl
Sep 27, 2007 12:44 PM | LINK
OK. Let me backpedal a little. I referenced the wrong library. I should have referenced Dave Relyea's layout framework that includes a Grid, StackPanel, Label, TextBox, etc....
All of the objects in this framework have properties named "GridColumn" and "GridRow" which are inherited from the base controls of the library. These properties can be set in your XAML as well as the IsHorizontal property of the StackPanel, Text property of the Label, etc... which are all custom properties defined in the code-behind of the control. Now, what I have noticed is that I can't set values to custom properties in XAML if the type of the property is that of a custom enum. I believe we come across this quite a bit in the SDK with the scrollbars.
balla
Member
674 Points
200 Posts
Re: First take on a UserControl
Sep 27, 2007 12:59 PM | LINK
You are right. It is the custom enumerations causing the trouble.[Y]