1
希望有一個簡單的問題。我有一個包含另一個自定義控件列表的依賴項屬性的自定義控件。無法序列化泛型類型'System.Windows.FreezableCollection`
public static readonly DependencyProperty BlockObjectsProperty = DependencyProperty.Register("BlockObjects", typeof(FreezableCollection<BlockObject>), typeof(Block), new FrameworkPropertyMetadata(new FreezableCollection<BlockObject>(), null));
public FreezableCollection<BlockObject> BlockObjects
{
get { return (FreezableCollection<BlockObject>)base.GetValue(BlockObjectsProperty); }
set { base.SetValue(BlockObjectsProperty, value); }
}
這則XAML中使用填充控制
<Viewbox Grid.Row="2" Stretch="Uniform">
<ItemsControl x:Name="tStack" ItemsSource="{TemplateBinding BlockObjects}" ContextMenu="{StaticResource BodyContextMenuKey}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Viewbox>
我現在的問題是我想序列這一點的文件,但我得到「無法序列化泛型類型」系統.Windows.FreezableCollection`'時使用XamlWriter.Save。如果這是一個普通的類,我可以使用屬性來描述它應該被序列化的方式(對嗎?),但是它是一個靜態依賴屬性,所以我如何得到這個序列化?
難以置信,但卻是事實!這對ObservableCollection <>也是有效的 – Ozzy 2017-05-30 21:19:25