wpf 命名空间前缀“system”未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28890180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The namespace prefix "system" is not defined
提问by Brad
I am getting an error on my XAML markup. I am trying to bind a master/child data grid to a dataset (dataset is linked to a SQLite database). My XAML is:
我的 XAML 标记出现错误。我正在尝试将主/子数据网格绑定到数据集(数据集链接到 SQLite 数据库)。我的 XAML 是:
<Window x:Class="TabletTester7.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TabletTester7"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ObjectDataProvider x:Key="FeaturesDataProvider"
ObjectType="{x:Type local:FeaturesDataProvider}"/>
<ObjectDataProvider x:Key="ChannelsDataProvider"
ObjectType="{x:Type local:ChannelsDataProvider}"/>
<ObjectDataProvider x:Key="Feature"
ObjectInstance="{StaticResource FeaturesDataProvider}"
MethodName="GetDefaultView"/>
<ObjectDataProvider x:Key="ChannelsByFeature"
ObjectInstance="{StaticResource ChannelsDataProvider}"
MethodName="GetChannelsByFeature">
<ObjectDataProvider.MethodParameters>
<x:Static Member="system:String.Empty"/> <!--Error here-->
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid Margin="0,0,0,-2">
<DataGrid Name="dgFeatures" ItemsSource="{Binding Source={StaticResource Feature}}"
Margin="0,0,0,179"
AutoGenerateColumns="False"
IsSynchronizedWithCurrentItem="false"
RowEditEnding="dataGrid_RowEditEnding"
SelectedValuePath="Feature_Id"
SelectionChanged="dgFeatures_SelectionChanged"
Grid.Row="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Feature ID" Binding="{Binding Feature_Id}"></DataGridTextColumn>
<DataGridTextColumn Header="Feature ID" Binding="{Binding Feature_Name}"></DataGridTextColumn>
<DataGridTemplateColumn Header="Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Date}" BorderThickness="0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<DataGrid Name="dhChannel"
ItemsSource="{Binding Source={StaticResource ChannelsByFeature}}"
Margin="0,148,0,0"
Grid.Row="1"
AutoGenerateColumns="False"
>
<DataGrid.Columns>
<DataGridTextColumn Header="Channel Path" Binding="{Binding Channel_Path}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
The method I am trying to call has a signature of
我试图调用的方法有一个签名
public DataView GetChannelsByFeature(string featureId)
On the line <x:Static Member="system:String.Empty"/>I get two errors:
在线上<x:Static Member="system:String.Empty"/>我收到两个错误:
The namespace prefix "system" is not defined.
and
和
String is not supported in a Windows Presentation Foundation (WPF) project.
How can I define this method parameter?
我如何定义这个方法参数?
回答by Rohit Vats
You have to declare system namespace before using it.
您必须在使用之前声明系统命名空间。
<ObjectDataProvider x:Key="ChannelsByFeature"
xmlns:system="clr-namespace:System;assembly=mscorlib" <!-- HERE -->
ObjectInstance="{StaticResource ChannelsDataProvider}"
MethodName="GetChannelsByFeature">
<ObjectDataProvider.MethodParameters>
<x:Static Member="system:String.Empty"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

