Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parser.SaveAsXml() doesn't save binding information

9 views
Skip to first unread message

MikeH

unread,
Feb 11, 2005, 7:09:02 PM2/11/05
to
It seems that Parser.SaveAsXml() doesn't save binding information. I
programmatically bound a dependency property to a data source, and expected
that the saved XAML would serialize the property value as something like
RadiusX="*Bind(Path=xxx)". But it just serialized the current value.

Is this a deliberate design decision, or just an omission? I tried using a
XamlDesigner to format the binding information, but OnSaveProperty() was not
called for the bound property. Apparently the binding causes the property to
be saved with compound property syntax, so OnSaveProperty() was not called.

I'm using the November CTP version of Avalon. Any insight would be much
appreciated.

Nick Kramer [MSFT]

unread,
Feb 11, 2005, 10:30:15 PM2/11/05
to
What you've described is the difference between
ExpressionSerializationMode.Implicit (what you're getting) and
ExpressionSerializationMode.Expression (what you want). [1] You use that
by setting the ExpressionSerializationMode property on the
XamlDesignerSerializationManager [2], which you pass into SaveAsXml [3].

Could you elaborate on what you're trying to do? Here's why I ask -- in
general, there is no right way for SaveAsXml to write out expressions and
events, because the information we need to serialize out was lost when the
document was loaded. (E.g., how do you serialize a delegate?) Fortunately,
the person calling SaveAsXml may know the right answer, so we have various
callbacks for that. So for example, if you're writing a visual designer you
store off certain information when the tree is created, and then use the
callbacks to help SaveAsXml serialize things how you want. But, doing that
is a nontrivial amount of work, and at present these callbacks are not real
well-documented, so I'd like to understand what you're doing before sending
you down this path. Thanks.

[1]
http://winfx.msdn.microsoft.com/winfx/ref/ns/system.windows.serialization/e/expressionserializationmode/expressionserializationmode.aspx
[2]
http://winfx.msdn.microsoft.com/winfx/ref/ns/system.windows.serialization/c/xamldesignerserializationmanager/xamldesignerserializationmanager.aspx
[3]
http://winfx.msdn.microsoft.com/winfx/ref/ns/system.windows.serialization/c/parser/m/saveasxml4.aspx

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"MikeH" <Mi...@discussions.microsoft.com> wrote in message
news:82469EB8-B701-40B9...@microsoft.com...

Vash

unread,
Feb 14, 2005, 4:04:12 AM2/14/05
to
Interesting material.

Something slightly offtopic about SaveAsXml:
Why is SaveAsXml being called twice in all examples i see on the net?
Parser.SaveAsXml(main, xtw, xamldesigner);
Parser.SaveAsXml(main);

In my testing it made no difference if I removed the second call.

"Nick Kramer [MSFT]" <nkr...@ms.spam> wrote in message
news:O1e8tMLE...@TK2MSFTNGP10.phx.gbl...

Vash

unread,
Feb 14, 2005, 4:40:37 AM2/14/05
to
These are two of the overloads of SaveAsXml:

public static void SaveAsXml(object, XamlDesignerSerializationManager);
public static void SaveAsXml(object, XmlWriter, XamlDesigner);

Whats the relation between XamlDesignerSerializationManager and
XamlDesigner?
This would mean that if I use the first overload I can't use a XamlDesigner?


"Nick Kramer [MSFT]" <nkr...@ms.spam> wrote in message
news:O1e8tMLE...@TK2MSFTNGP10.phx.gbl...

MikeH

unread,
Feb 14, 2005, 6:51:02 PM2/14/05
to
Setting XamlDesignerSerializationManager.ExpressionSerializationMode =
ExpressionSerializationMode.Expression gave me exactly the results I was
looking for. Thanks very much for your help! (I was also able to get what I
needed by overriding XamlDesigner.OnSaveNode(), and checking if the "token"
parameter was equal to XamlNodeType.PropertyComplexStart. But your way is
much cleaner.)

I'm working on a designer app that lets the user create data bound drawings
and forms. We don't need event handlers to be serialized, since we handle all
the events on behalf of the user. But we need to programmatically add/remove
binding information, and serialize/de-serialize it to/from XAML. Since the
binding information is stored in the tree (or at least accessible via
FrameworkObject.GetBinding()), this is pretty easy to do. Thanks again for
your help!

Nick Kramer [MSFT]

unread,
Feb 14, 2005, 11:28:21 PM2/14/05
to
I'm hard pressed to imagine why someone would call SaveAsXml() twice in a
row. SaveAsXml doesn't have any side effects (other than the obvious of
writing to the stream/writer).

--

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Vash" <vashist[at]wanadoo.nl> wrote in message
news:eHzMoQnE...@tk2msftngp13.phx.gbl...

Nick Kramer [MSFT]

unread,
Feb 14, 2005, 11:35:15 PM2/14/05
to
Someone reminded me on another thread [1], one of the things you can't do
without the serialization callbacks is write out xaml with bitmaps, because
the .jpg/.bmp/etc files themselves aren't in xaml. Something to keep in
mind if bitmaps are part of your designer.

[1] SaveAsXml(): When to use?

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"MikeH" <Mi...@discussions.microsoft.com> wrote in message

news:239D897A-87D3-443A...@microsoft.com...

Vash

unread,
Feb 15, 2005, 3:38:09 AM2/15/05
to
> I'm hard pressed to imagine why someone would call SaveAsXml() twice in a
> row.

These two lines of code come straight from theWinFX SDK documentation ;)
>> Parser.SaveAsXml(main, xtw, xamldesigner);
>> Parser.SaveAsXml(main);


Vash

unread,
Feb 15, 2005, 4:23:27 AM2/15/05
to
Ok this was a stupid question. Should have looked at the
XamlDesignerSerializationManager constructor:
public XamlDesignerSerializationManager(XmlWriter, XamlDesigner);

"Vash" <vashist[at]wanadoo.nl> wrote in message

news:O2EO%23knEF...@TK2MSFTNGP14.phx.gbl...

Nick Kramer [MSFT]

unread,
Feb 15, 2005, 3:51:21 PM2/15/05
to
Thanks, I'll enter a bug on that.

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Vash" <vashist[at]wanadoo.nl> wrote in message

news:%23Rguumz...@tk2msftngp13.phx.gbl...

0 new messages