命名空间前缀" system"没有定义

时间:2015-03-06 00:05:14

标签: c# wpf xaml

我的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>

我试图调用的方法有

的签名
public DataView GetChannelsByFeature(string featureId)

<x:Static Member="system:String.Empty"/>行上,我收到两个错误:

The namespace prefix "system" is not defined.

String is not supported in a Windows Presentation Foundation (WPF) project.

如何定义此方法参数?

1 个答案:

答案 0 :(得分:9)

您必须在使用之前声明系统命名空间。

<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>