質問

I have a tab control with the content being a WPF Toolkit Datagrid. The tab control is bound to a dictionary (Model.Radios in the code below). The value of the dictionary entry is a custom list derived from the CSLA BusinessListBase class. All that works, but when I click on a cell in the datagrid I keep getting an exception that certain classes aren't marked as serialized. First it was the list class, then it complained about the class that makes up the list items. The items of the list is in a class hierarchy about 6 classes deep, so after I marked a few classes as Serializable I started to wonder if this is necessary. It's been a while since I've used the datagrid but I swear I didn't run into this the last time I used it and it just worked. Is there something I am missing? Maybe this has something to do with CSLA and not the data grid... Not sure.

<TabControl Grid.Row="1" Name="myTabControl" ItemsSource="{Binding Model.Radios}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding (collections:DictionaryEntry.Key)}"></TextBlock>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <tk:DataGrid ItemsSource="{Binding (collections:DictionaryEntry.Value)}" AutoGenerateColumns="False" >
                    <tk:DataGrid.Columns>
                        <tk:DataGridTextColumn Header="Number" Binding="{Binding PresetNumber}" IsReadOnly="True" Width="Auto"/>
                        <tk:DataGridTextColumn Header="Identifier" Binding="{Binding Identifier}" />
                        <tk:DataGridTextColumn Header="Frequency" Binding="{Binding Frequency}" />
                    </tk:DataGrid.Columns>
                </tk:DataGrid>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
役に立ちましたか?

解決

Each class in the object graph should be marked as [Serializable], including any base classes (you can confirm this by looking at the CSLA source code for the base classes; they're all serializable); CSLA is trying to serialize the entire graph to your WPF app, and if one isn't there, it'll break.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top