我在一个新的 C# 项目的主窗口中添加了一个 Image 对象
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150*" />
<RowDefinition Height="161*" />
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Height="240" HorizontalAlignment="Left" Margin="80,26,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="320" DataContext="{Binding ElementName=image1}" />
<TextBox Grid.Row="1" Height="25" HorizontalAlignment="Left" Margin="155,119,0,0" Name="kinectStatusTB" VerticalAlignment="Top" Width="111" Text="Disconnected" DataContext=" {Binding}" />
<TextBlock Grid.Row="1" Height="18" HorizontalAlignment="Left" Margin="80,122,0,0" Name="textBlock1" Text="Kinect Status" VerticalAlignment="Top" Width="69" />
</Grid>
</Window>
我在 .cs 代码中的这一行出现错误,提示“当前上下文中不存在名称‘image1’”
image1.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height,
96, 96, //DPI
PixelFormats.Bgr32, //format
null,
pixels, //where the data is stored
stride);
我不知道我是否做错了,我对 C# 还很陌生。