无法转换属性“Property”中的值类型为“System.Windows.DependencyProperty”的对象
我有选项卡控件,其中一个选项卡包含 DataGrid 第二个 ColumnSeries 图表,当我按下图表选项卡时,我收到这样的错误:
无法将属性“Property”中的值转换为“System.Windows.DependencyProperty”类型的对象。 无法从文本“Background”创建“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>
I have tab control one tab contains DataGrid second ColumnSeries chart when i press when i press charts tab i'm getting such error:
Cannot convert the value in attribute 'Property' to object of type 'System.Windows.DependencyProperty'.
Failed to create a 'DependencyProperty' from the text 'Background'.
i don't have any event on tab control, this is my 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>
and Chart:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的问题是在背景=“红色”的区域系列内引起的。 DataPointStyle实际上有背景。
暂时删除它,如果它解决了您的问题,那么我认为您想要访问区域系列的 DataPointStyle 来设置背景。
看看这个:
编辑
:删除了我的xaml示例,作为直接设置代替样式确实有效。
I think your issue is caused inside the areaSeries with Background="Red". The DataPointStyle actually has the background.
Remove that temporarily and if it solves your problem then I think you want to access the DataPointStyle of your area series to set the background.
Check this out:
wpf Area Chart with Different Colors?
Edit: Removed my xaml example, as a direct setting in place of styles does work.
这可能是 Microsoft Toolkit 本身的错误。
http://wpf.codeplex.com/workitem/12865
我遇到了完全相同的问题,现在我将尝试删除错误并重新编译工具包。
This could be a bug in the Microsoft Toolkit itself.
http://wpf.codeplex.com/workitem/12865
I had exactly the same problem and now I'm going to try to remove the bug and recompile the toolkit.