找不到类型或命名空间名称(XAML新增function)

所以我正在尝试使用Visual Studio 2012在XAML文档上使用一个非常简单的骰子应用程序,但我无法弄清楚如何处理错误。 我尝试使用bitmapimage添加; 但它仍然行不通。

以下是我得到的错误:

Error 1 Undefined namespace. The 'using' URI refers to a namespace 'DiceRoll' that could not be found. Error 2 The type or namespace name 'BitmapImage' could not be found (are you missing a using directive or an assembly reference?) 

CS:

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using BitmapImage; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 namespace DiceRoll { ///  /// Interaction logic for MainWindow.xaml ///  public partial class MainPage : Page { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { Random num = new Random(); int Number = num.Next(1, 7); BitmapImage Img = new BitmapImage(new Uri(@"DiceFaces\" + Number.ToString() + ".bmp", UriKind.Relative)); textBlock1.Text = Number.ToString() + " Number"; image1.Source = Img; } } } 

XAML:

    

尝试

 using System.Windows.Media.Imaging.BitmapImage; 

代替

 using BitmapImage; 

更简单的方法是让Visual Studio为您完成:右键单击代码中的BitmapImage – > resolve,然后选择正确的命名空间(通常只有一个)

对于xaml,让Visual Studio也为你做,或者: