Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - bug in xaml serialization of Int32Collection

 
 
Old 05-19-2007   #1 (permalink)
Robert Ludig


 
 

bug in xaml serialization of Int32Collection

I have introduced an attached DependencyProperty
"CustomControl1.IntsProperty" of type Int32Collection. So I *should be
able to use it like this:

<Window x:Class="WPFApplication5.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window1_Loaded"
xmlns:y="clr-namespace:WPFApplication5">
<StackPanel x:Name="MyPanel">
<Button y:CustomControl1.Ints="2 3 5">eins</Button>
<Button y:CustomControl1.Ints="2,3,5">zwei</Button>
<Button y:CustomControl1.Ints="2,3">drei</Button>
<Button y:CustomControl1.Ints="2 3">vier</Button>
<Button y:CustomControl1.Ints="2 ">fnf</Button>
<Button y:CustomControl1.Ints="2">sechs</Button>
</StackPanel>
</Window>

I defined the property inside CustomControl1 like this:

Code Snippet
#region Ints

public static void SetInts(UIElement element, Int32Collection value)
{
element.SetValue(IntsProperty, value);
}
public static Int32Collection GetInts(UIElement element)
{
return (Int32Collection)element.GetValue(IntsProperty);
}
public Int32Collection Ints
{
get { return (Int32Collection)GetValue(IntsProperty); }
set { SetValue(IntsProperty, value); }
}
public static readonly DependencyProperty IntsProperty =
DependencyProperty.RegisterAttached("Ints", typeof(Int32Collection),
typeof(CustomControl1),
new FrameworkPropertyMetadata(new Int32Collection(0),
FrameworkPropertyMetadataOptions.AffectsMeasure |
FrameworkPropertyMetadataOptions.AffectsMeasure));
#endregion Ints

And I query the values in Window.Loaded eventhander like this:

public void Window1_Loaded(object sender, RoutedEventArgs args)
{
foreach (DependencyObject depObj
in LogicalTreeHelper.GetChildren(this.MyPanel))
{
Int32Collection ints =
(Int32Collection)depObj.GetValue(CustomControl1.IntsProperty);
Console.WriteLine(depObj.ToString() + " " + ints.ToString());
}
}
It seems as if the Int32CollectionValueSerializer is not doing his job
and the values it did not get deserialized from XAML/string correctly.
Only the the values "2 3 5" and the values "2,3,5" can be found. The
rest of the Int32Collections where the values in xaml have been "2,3"
"2 3" "2" and "2 " are empty.

Another very intersting phenomenon is that the designer of visual
studio Orcas Beta 1 (wich I used for this example) acutually gets it
right ! When the Designer creates and shows the wpf window embedded
in visual studio all 6 buttons have the correct values.

How come this happens? And what can I do against that? Is this a bug
in visual studio orcas ? I hope it is not abug in .NET 3.0


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Is it possible to include XAML files into another XAML file? .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46