Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:21:58+00:00 2026-06-18T15:21:58+00:00

I’m a total noob with basic experience in javascript but really would like to

  • 0

I’m a total noob with basic experience in javascript but really would like to learn c#net programming to make phone apps. The app I’m trying to do needs me to be able to set a custom property on certain xaml elements.

I found what seems to be a simple exemple of this on stackoverflow (Adding custom attributes to an element in XAML?) and didn’t get it work. I then read a lot of documentation everywhere and feel more confused than ever…I think I got the concept right, but my implementation is not. For exemple, if I just copy thecode from the page I mentionned, I get this:

Mainpage.xaml

<phone:PhoneApplicationPage 
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:local="clr-namespace:MyNamespace" //<--ADDED BY ME
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"

shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->


    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
</Grid>
</phone:PhoneApplicationPage>

Mainpage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{

    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }
 }
namespace MyNamespace
{
    public static class MyClass
    {

        public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.RegisterAttached("MyProperty",
            typeof(string), typeof(MyClass), new FrameworkPropertyMetadata(null));

        public static string GetMyProperty(UIElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");
            return (string)element.GetValue(MyPropertyProperty);
        }
        public static void SetMyProperty(UIElement element, string value)
        {
            if (element == null)
                throw new ArgumentNullException("element");
            element.SetValue(MyPropertyProperty, value);
        }
    }
}
}

From there, I can’t add any visual element because I have this error:

Error 1 The type or namespace name ‘FrameworkPropertyMetadata’ could not be found (are you missing a using directive or an assembly reference?)

Now, if this code worked, from what I understand, the attached property would only be avalaible to objetc of my class… How do you bind a xaml element and a c#class?

If you see where i’d like to go, any informatio you have will be appreciated. I already spent hours on this little detail…

Many thanks in advance!!!!!!!!!!!!!
(Yes, I’m a noob…I have some c#books ordered that are coming, I checked many sites but still nedd guidance..thanks again)

EDIT:
Follow up: The suggestion given to me worked and let me compile but:

The xmlns:local=”clr-namespace:MyNamespace” gives me this error:

Undefined CLR namespace. The ‘clr-namespace’ URI refers to a namespace ‘MyNamespace’ that is not included in the assembly. Do I need that line?

From there I can’t add any other element. If I do remove that line, and add an ellipse, for exemple, I can’t give it a MyProperty, VS tells me that :

The Property’MyProperty’ was not found in type Ellipse.

I understand I registered ‘MyProperty’ for MyClass. Well, How do I give an Ellipse a class of ‘MyClass’? Should I take another approach? Can I use ‘MyProperty’ on anything I want? Any tips highly appreciated, THANKS!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:21:59+00:00Added an answer on June 18, 2026 at 3:21 pm

    Everything looks fine for the most part.
    You just need to change FrameworkPropertyMetadata to PropertyMetadata, and the code should compile just fine.

    Update: The XAML namespace is actually wrong. You have defined MyNamespace inside the PhoneApp1 namespace. Therefore the complete namespace is PhoneApp1.MyNamespace

    xmlns:local="clr-namespace:PhoneApp1.MyNamespace"
    

    This article has more on xaml namespaces in Silverlight

    Applying your attached property is simple enough once you have the namespace sorted. In fact, you have used an attached property already

    shell:SystemTray.IsVisible=”True”

    Your attached property will be applied like so:

    <Grid local:MyClass.MyProperty="Value" />
    

    This article about Attached Properties should help

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.