views:

109

answers:

2

Hi, I am trying to create DependencyProperties that have a nice drop down code completion when using them in the XAML-editor in Visual Studio.

Many default SilverLight framework properties have such completion, e.g., Background or BorderBrush. Also, Boolean Properties show the True/False selection in the XAML-editor. The same holds true for DependencyProperties, such as Canvas.Top and Canvas.Left, etc.

I tried to define my own DependencyProperties of type Color or Boolean, since i believed that default types like Color, Brush, and Boolean might get completion for free. This did not happen.

I believe that i have to define some annotations for my properties, but did not find an example since the Silverlight SDK only shows the public API in Visual Studio, and not the internals.

Do you have an idea, how to get code completed Properties?

Update: Here is an example of what I am trying to do in SilverLigth 3 (!) I just talked to a colleage, and he believes that the problem is related to Silverlight 3 and the old non-VS2010-XAML-editor in VS 2008.

XAML:

<Grid x:Name="LayoutRoot">
  <Border test:PropTest.Test="Blue">
    <TextBlock Text="123"/>
  </Border>
</Grid>

Code behind

namespace PropTest{
  public class PropTest : DependencyObject {
    public static readonly DependencyProperty TestProperty = DependencyProperty.RegisterAttached(
      "Test", typeof(Color), typeof(PropTest), new PropertyMetadata(Colors.Red));

    public static void SetTest(DependencyObject obj, Color color){
      (obj as Border).Background = new SolidColorBrush(color);
    }
    public static Color GetTest(DependencyObject obj){
      return Colors.Red;
    }
  }
}

This example is compileable/runnable, but I want to write an API using DependencyProperties and not an application and thus I want code completion for my API. :)

+2  A: 

You do not need to do anything special to get the intellisense help for known types. For example Brush, Color or Boolean. However intellisense is a little slow in VS2008 and can take quite a while to build. It can be quite tempermental even on built-in controls.

If your objects are in the same project a the Xaml you are editing try building the project.

The only other thing you can do is just be patient with it.

AnthonyWJones
+1  A: 

I just found the solution, at least for Color it is working now. I will try to test it with other Types. I placed my code directly into the application, which was, first, a bad practice, since I am trying to write an API, and second, caused the missing code completion.

The Property-related code above should go into a separate library and be referenced by the project using the code (e.g., an application). Then it is working.

The next thing I will try, is to write my own completion class similar to the Colors class for the Color type and see if i can code compeltion for my own types. but maybe that is another question.

Juve