无法将属性“Property”中的值转换为“System.Windows.DependencyProperty”类型的对象

时间:2011-11-23 13:12:28

标签: c# wpf exception-handling charts wpftoolkit

我有选项卡控件一个选项卡包含DataGrid第二个ColumnSeries图表,当我按下我按下图表选项卡时我得到这样的错误:

  

无法将属性“Property”中的值转换为“System.Windows.DependencyProperty”类型的对象。   无法从文本“背景”创建“DependencyProperty”。

我没有关于制表符控件的任何事件,这是我的DataGrid:

<TabControl Name="tabControl1">
    <TabItem Name="tabItem1" Header="Logs">
        <Grid>
            <Grid Background="#FFABABAB">
                <Border Name="border1" BorderBrush="Silver" BorderThickness="1" Height="92" VerticalAlignment="Top" Background="AliceBlue" Margin="0,0,1,0">
                    <Grid>
                        <Button Name="btnGridToExcel" Content="Export To Excel" Height="23" HorizontalAlignment="Left" Margin="639,58,0,0" VerticalAlignment="Top" Width="92" Click="btnGridToExcel_Click" />
                        <Button Name="btnReset" Content="Reset/Refresh" Height="23" HorizontalAlignment="Left" Margin="639,24,0,0" VerticalAlignment="Top" Width="92" Click="btnReset_Click" />
                    </Grid>
                </Border>
                <DataGrid Name="dataGrid1" AutoGenerateColumns="false" Margin="0,91,1,32" SelectedValuePath="ID" SelectionMode="Extended" 
                          SelectionUnit="CellOrRowHeader" CanUserReorderColumns="false" CanUserAddRows="false" CanUserDeleteRows="false" 
                          IsReadOnly="true" AlternatingRowBackground="#FFF2F4F4" RowBackground="#FFE0E4E3" ItemsSource="{Binding ActionCollection}" 
                          SelectedCellsChanged="dataGrid1_SelectedCellsChanged" >
                    <DataGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Name="MenuItemEdit" Header="Edit" Click="MenuItemEdit_Click">
                                <MenuItem.Icon>
                                    <Image Source="/H-Pro;component/Images/1314285611_edit.png"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Name="MenuItemDelete" Header="Delete" Click="MenuItemDelete_Click">
                            <MenuItem.Icon>
                                    <Image Source="/H-Pro;component/Images/1314285495_dialog-close.png"/>
                            </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem Name="MenuItemPayment" Header="Pay selected" Click="MenuItemPayment_Click">
                                <MenuItem.Icon>
                                    <Image Source="/H-Pro;component/Images/1314875051_money_dollar.png"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" Binding="{Binding Path=ID, Mode=OneWay}" />
                        <DataGridTextColumn Header="RoomType" Binding="{Binding Path=RoomType, Mode=OneWay}" />
                        <DataGridTextColumn Header="Room" Binding="{Binding Path=RoomNumber, Mode=OneWay}" />
                        <DataGridTextColumn Header="Guest" Binding="{Binding Path=GuestName, Mode=OneWay}" />
                        <DataGridTextColumn Header="Persons" Binding="{Binding Path=Person, Mode=OneWay}" />
                        <DataGridTextColumn Header="Check In" Binding="{Binding Path=CheckInDate, Mode=OneWay}" />
                        <DataGridTextColumn Header="Check Out" Binding="{Binding Path=CheckOutDate, Mode=OneWay}" />
                        <DataGridTextColumn Header="Room Price" Binding="{Binding Path=RoomPriceWithCurrency, Mode=OneWay}" />
                        <DataGridCheckBoxColumn Header="Inc. First Day" Binding="{Binding Path=IncFirstDay, Mode=OneWay}" />
                        <DataGridTextColumn Header="Discount %" Binding="{Binding Path=Discount, Mode=OneWay}" />
                        <DataGridTextColumn Header="Discounted Price" Binding="{Binding Path=DiscountedPriceWithCurrency, Mode=OneWay}" />
                        <DataGridTextColumn Header="Rate" Binding="{Binding Path=Rate, Mode=OneWay}" />
                        <DataGridTextColumn Header="Total Days" Binding="{Binding Path=TotalDays, Mode=OneWay}" />
                        <DataGridHyperlinkColumn Header="Services" Binding="{Binding Path=TotalServiceCount, Mode=OneWay}" >
                            <DataGridHyperlinkColumn.ElementStyle>
                                <Style TargetType="TextBlock">
                                    <EventSetter Event="Hyperlink.Click" Handler="DG_Hyperlink_Click" />
                                </Style>
                            </DataGridHyperlinkColumn.ElementStyle>
                        </DataGridHyperlinkColumn>
                        <DataGridTextColumn Header="Total Price" Binding="{Binding Path=TotalPrice, Mode=OneWay}" />
                        <DataGridTextColumn Header="Total Price in Gel" Binding="{Binding Path=TotalPriceInGel, Mode=OneWay}" />
                        <DataGridTextColumn Header="Paid" Binding="{Binding Path=PaidMoney, Mode=OneWay}" />
                        <DataGridTextColumn Header="Debt" Binding="{Binding Path=Debt, Mode=OneWay}" />
                        <DataGridTextColumn Header="Invoice #" Binding="{Binding Path=InvoiceNumber, Mode=OneWay}" />
                    </DataGrid.Columns>
                    <DataGrid.GroupStyle>
                        <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <DataGridRowsPresenter />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </DataGrid.GroupStyle>
                </DataGrid>
            </Grid>
        </Grid>
    </TabItem>
</TabControl>

和图表:

<TabItem Header="Statistic">
    <ScrollViewer>
        <Grid Background="White">
            <Button Name="button1" Content="Button" Height="23" HorizontalAlignment="Left" Margin="348,6,0,0" VerticalAlignment="Top" Width="75" />
                <charting:Chart Name="ChartGuests66" Margin="6,48,87,262" Width="862" Height="451">
                    <charting:AreaSeries DependentValuePath="Value" IndependentValuePath="Key" Background="Red">
                    <charting:DataPointSeries.ItemsSource>
                        <Binding BindsDirectlyToSource="True"/>
                    </charting:DataPointSeries.ItemsSource>
                </charting:AreaSeries>
            </charting:Chart>
        </Grid>
    </ScrollViewer>
</TabItem>

2 个答案:

答案 0 :(得分:4)

我认为你的问题是在带有Background =“Red”的areaSeries中引起的。 DataPointStyle实际上具有背景。

暂时删除它,如果它解决了你的问题,那么我想你想访问你的区域系列的DataPointStyle来设置背景。

检查一下: wpf Area Chart with Different Colors?

编辑:删除了我的xaml示例,因为直接设置代替样式确实有效。

答案 1 :(得分:1)

这可能是Microsoft Toolkit本身的一个错误。 http://wpf.codeplex.com/workitem/12865

我有完全相同的问题,现在我将尝试删除该错误并重新编译该工具包。