代码之家  ›  专栏  ›  技术社区  ›  whytheq

无法识别WPF InitializeComponent

  •  0
  • whytheq  · 技术社区  · 6 年前

    <Window x:Class="Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Northwind Orders" Height="335" Width="425" 
            Name="OrdersWindow" Loaded="Window1_Loaded">
        <Grid Name="orderItemsGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="258*"/>
                <ColumnDefinition Width="161*"/>
            </Grid.ColumnDefinitions>
            <ComboBox DisplayMemberPath="OrderID" ItemsSource="{Binding}"
                      IsSynchronizedWithCurrentItem="true" 
                      Height="23" Margin="92,12,37.703,0" Name="comboBoxOrder" VerticalAlignment="Top"/>
            <DataGrid ItemsSource="{Binding Path=Order_Details}"  
                      CanUserAddRows="False" CanUserDeleteRows="False"  
                      Name="orderItemsDataGrid" Margin="34,46,34.4,49.6"
                      AutoGenerateColumns="False" Grid.ColumnSpan="2">
                <DataGrid.Columns>
                    <DataGridTextColumn  Header="Product" Binding="{Binding ProductID, Mode=OneWay}" />
                    <DataGridTextColumn  Header="Quantity" Binding="{Binding Quantity, Mode=TwoWay}" />
                    <DataGridTextColumn  Header="Price" Binding="{Binding UnitPrice, Mode=TwoWay}" />
                    <DataGridTextColumn  Header="Discount" Binding="{Binding Discount, Mode=TwoWay}" />
                </DataGrid.Columns>
            </DataGrid>
            <Label Height="28" Margin="34,12,0,0" Name="orderLabel" VerticalAlignment="Top" 
                   HorizontalAlignment="Left" Width="65">Order:</Label>
            <StackPanel Name="Buttons" Orientation="Horizontal" HorizontalAlignment="Right" 
                        Height="40" Margin="0,261,22.4,4.6" Grid.ColumnSpan="2">
                <Button Height="23" HorizontalAlignment="Right" Margin="0,0,12,12" 
                    Name="buttonSave" VerticalAlignment="Bottom" Width="75" 
                        Click="buttonSaveChanges_Click">Save Changes
                </Button>
                <Button Height="23" Margin="0,0,12,12" 
                    Name="buttonClose" VerticalAlignment="Bottom" Width="75" 
                        Click="buttonClose_Click">Close</Button>
            </StackPanel>
        </Grid>
    </Window>
    

    所以我把它换了,但是现在如果我去查文件 MainWindow.xmal.cs InitializeComponent(); 正在突出显示为不存在。

    enter image description here

    这是为什么?我该如何纠正它?

    1 回复  |  直到 6 年前
        1
  •  4
  •   Cinchoo    6 年前

    你必须符合标准 x:Class="Window1" 在XAML中使用代码隐藏类 class MainWindow .

    将XAML从 x:Class=“Window1” x:Class="NorthwindClient.MainWindow"