PropertyValueEditor and DependencyObject in Blend 3 - Silverlight DesignTime support

I'm working on a set of controls that has a number of DependencyProperties. The properties are themselves DependencyObjects and created during the get method of the properties. During the Get method, they are also set back to the propertybag using the SetValue() method, so they are in fact valid in Xaml and their properties can be storyboarded without having to explicitly created in the the visual tree.

These DependencyObjects has all its properties as DependencyProperties as well, for supporting DataBinding. They are as mentioned above possible to use in Storyboards.

At the same time I'm developing special designtime support for Blend 3 for these properties and have created an InlineEditorTemplate in the form of a Control. I create the template and set it for the PropertyValueEditor like this:

var vectorEditControl = new FrameworkElementFactory(typeof (VectorEditorControl)); var dataTemplate = new DataTemplate {VisualTree = vectorEditControl}; InlineEditorTemplate = dataTemplate;

In the Control I have the following:

<Grid DataContext="{Binding Value}">

<StackPanel Orientation="Horizontal"> <TextBox Text="{Binding Path=X, Mode=TwoWay}"/> <TextBox Text="{Binding Path=Y, Mode=TwoWay}"/> <TextBox Text="{Binding Path=Z, Mode=TwoWay}"/> </StackPanel>


The editor shows up and I can edit the data. And even while debugging, I see that it actually sets the data back to the DependencyProperties on the DependencyObjects, but nothing happens to the Xaml. So the data is actually not persisted in any way in the Xaml and lost when I close the Xaml file and open it again.

Is there anything I need to do specifically for it to actually get into the Xaml? I was under the impression that this would happen automatically?

-------------Problems Reply------------

Excellent Question!

The core issue you're running into a misunderstanding as to what PropertyEditors in Blend/Cider end up databinding to.

Consider this object graph:
- MyControl
-- MyControl.MyProperty
--- FooClass
---- FooClass.BarProperty

Let's look at a scenario where we have a PropertyEditor (of any type: Inline, Dialog or Extended) to property MyControl.MyProperty. When inside MyPropertyPropertyEditor you'd expect to get a fully settable copy of FooClass and be able to manipulate it's members. That's a good assumption, but the wrong one.

The core issue is that Blend/Cider have elaborate data structures that represent your model at design time. There's about 3-5 levels of abstraction in how Blend/Cider interact with an actual control.
Creating those levels of abstraction allows Expression Blend / Visual Studio designers to be leveraged between framewroks (Silverlight / WPF) and support advanced scenarios (like Property transactions and property chaining).

So, the value you actually get to DataBind to is just one of those levels of abstraction.
Don't believe me? In your custom PropertyEditor, register for this.DataContextChanged event and checkout the type in this.DataContext. You'll end up getting the PropertyValue class (or one of it's friends).

Every single property change you want persisted to XAML (and shown on the design surface) should go through those abstraction layers.

the question you have to ask yourself is "Where do I get one of these absteaction classes for my PropertyValue.Value property instance?".

Well, what I'd do if I were you is create a ModelItem around MyControl.MyProperty and set that as your PropertyEditor.DataContext. We've shipped an example of using ModelFactory.CreateItem in the Silverlight Toolkit as part of the Chart DefaultInitializer: Source Code, Ning Zhang (Awesome Design Time Dev) explains about ModelItem

If you've got follow-up questions I'd consider pinging PeteBl or UnniR through the Silverlight Insiders mailing list.

-- Justin

It partly solves my problem. I'm having a dialog with UnniR for a followup. I couldn't see how I could use this together with the PropertyValueEditor, but for default values this is brilliant and something I'll implement ASAP.


Category:silverlight Views:0 Time:2009-11-24

Related post

  • Expression Blend 4.0 - What layer effects and blend modes are supported for imported Photoshop files? 2010-08-25

    Many Photoshop effects aren't property supported by Expression Blend. Usually I see an option to "flatten layer" to get around this problem. Is there a comprehensive list of what effects or blend modes are supported by Blend? I'm curious about the Si

  • Why do the assemblies in the Expression Blend SDK not support Application Library Caching? 2011-04-07

    Admittedly, creating extmap.xml files is relatively simple: But while many third-party libraries provide extmap.xml files with their assemblies (for instance, Telerik thankfully does), the

  • does silverlight 3 support GUID in xaml? 2009-12-15

    I have a question similar to this - Does Silverlight xaml support Byte Data Type. Does silverlight xaml support Guid datatype. I m trying to set Guid in my xaml which is a declared as property in c# class library. is this possible? I tried using xmln

  • Behaviors for Blend (Silverlight 4) 2010-06-02

    I'm wondering if anybody knows any good (free) behaviors for Blend/Silverlight 4 Specifically I'm looking for a behavior that I can drop on a TextBlock to make it scroll horizontally or a behavior that will "flash" text in a TextBlock (blinking text)

  • Using callouts in Expression Blend + Silverlight 2011-03-01

    I have an Expression Blend+Silverlight application that makes use of callouts. Now I want to show several strings each after a specified duration within a single callout. But I can't set the ContentProperty of the callout programmatically - it's thro

  • Silverlight browser support does not seem to be ubiquitous? 2008-12-12

    We have been using Adobe Flex for a major project but it's just too slow. We're considering switching to Silverlight. The problem seems to be that Silverlight is not as widely supported by browsers as Flex/Flash is. For example I tried to access the

  • Why does Silverlight not support compiled Regular Expressions? 2009-03-19

    The Silverlight 2 and Silverlight 3 Beta framework do not support compiled Regular Expressions i.e: RegexOptions.Compiled I'd be interested to hear the reasoning behind why this is the case if possible. --------------Solutions------------- I guess it

  • Does Silverlight XAML Support The Byte Data Type? 2009-07-30

    Here is my data type: using System; namespace UI { public class AddressType { public byte ID { get; set; } public string Name { get; set; } } } Here is my collection: using System.Collections.ObjectModel; namespace UI { public class AddressTypes : Ob

  • Microsoft Expression Blend (silverlight): repeating header? 2009-09-17

    Hi I'm using the new microsoft expression. I'm trying to create a repeating header much like this one at Is there a way I can do this in Expression blend. How do I organize the containers? And how do I set it to rep

  • Silverlight OOTB Support for 'Save File' browser dialog 2009-12-17

    I am in the design stage of an application that must be both a standalone app & a web application (To save the costs of building 2 near identical applications twice). Basically I have opted to go for a silverlight OOTB application that will be in

  • Will Silverlight be supported in Windows RT? 2012-03-17

    Will silverlight ever be supported for the Surface RT? It boggles my mind that this so called "flagship" tablet from Microsoft cant run simple video playing software also developed by Microsoft. --------------Solutions------------- Hi, Thank you for

  • When will silverlight be supported on the Surface RT? 2013-12-13

    Trying to dump the laptop for the first time in favor of the RT and just discovered that I am going to miss the first week of the Tour de France because of the lack of Silverlight support. Really!?! Microsoft ... get with it guys. This is a potential

  • Does Silverlight 4 support drag and drop from app to desktop? 2010-03-27

    I have seen that SL4 support drag and drop from the desktop to the application, but is it possible to drag and drop from the application to the desktop ? Thanks, --------------Solutions------------- No, it does not support this scenario.

  • Debug Visual Studio or Blend Silverlight / WPF designer load errors? 2010-08-10

    Is there a way to debug Visual Studio or Blend so I can figure out where XAML designer load errors come from in my code? The stack traces are often useless. Thanks... --------------Solutions------------- Use two VS2010 instances. Load one with your m

  • Blend/VS designer support for adding complex content based on boolean property 2010-09-17

    I have my own derived WPF DataVisualization chart control and within that control, I have a boolean property that the designer can set which in turn creates and adds a line series to that chart control. Now the problem is that I can easily create the

  • What's the largest resolution image file silverlight can support? 2011-03-21

    Just wondering as I'm debugging a problem related to image file sizes. Is there an upper limit? Or is it just limited by the GPU itself? What about the image file size? Thanks for any help! --------------Solutions------------- You've used the UPLOAD

  • Wrong assembly-references for Silverlight Sketchflow project in Blend 3 2010-04-08

    In my installation of Blend 3, the SketchStyles are missing when a new project is created. I found out that this is because the following automatic references in the project are wrong: Microsoft.Expression.Interactions Microsoft.Expression.Prototypin

  • Resharper support for Silverlight Unit Test Application 2010-05-25

    HI All Is there a version of Reshaper that can be used to run Silverlight unit test. I am using Resharper 4.5 although it shows test icons against test methods in the class, but it does actually run the test. Thanks --------------Solutions-----------

  • Silverlight Low Level Socket Support? 2010-10-29

    I have a Silverlight app that needs low-level socket support. It's an Out-of-Browser Trusted app, so it has more network permissions. But, I noticed that that Silverlight only supports limited TCP sockets, even with elevated permissions. The method "

Copyright (C), All Rights Reserved.

processed in 0.166 (s). 11 q(s)