0

我试图做的是使用silverlight在xna中创建一个弹出窗口,但它抛出一个错误,说'system.windows.media.color'和'Microsoft.xna.framework.color'的引用存在歧义,有没有解决方案...如果有的话,任何建议都会非常有用。

编辑:

好的,这已经奏效了,但我现在有另一个问题,出现一个错误,说“元素已经是另一个元素的子元素”......有人可以帮我吗?到达“myStackPanel.Children.Add(txtNameEntry);”时会引发错误 线...

  Border border = new Border();
                    border.BorderBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White);
                    border.BorderThickness = new Thickness(10);

                    StackPanel myStackPanel = new StackPanel();
                    myStackPanel.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);

                    //Textblock containing the name you input and its properties.
                    //txtNameEntry.Text = Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceName").ToString();
                    txtNameEntry.Text = "Player 1";
                    txtNameEntry.Width = 350;
                    txtNameEntry.Height = 100;
                    txtNameEntry.MaxLength = 10;
                    txtNameEntry.FontFamily = new System.Windows.Media.FontFamily("Comis Sans MS");
                    txtNameEntry.FontSize = 48.0;
                    //txtNameEntry.Foreground = new System.Windows.Media.FontFamily(Colors.Orange);
                    txtNameEntry.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Orange);
                    txtNameEntry.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightGray);
                    txtNameEntry.BorderBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightGray);

                    //The ok button, which then allows you to procede into the game.
                    Button btnNameEntryOK = new Button();
                    btnNameEntryOK.Content = "Ok";
                    btnNameEntryOK.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Orange);
                    btnNameEntryOK.FontFamily = new System.Windows.Media.FontFamily("Comic Sans Ms");
                    btnNameEntryOK.FontSize = 25.0;
                    btnNameEntryOK.Width = 180;
                    btnNameEntryOK.Height = 70;
                    btnNameEntryOK.Click += new RoutedEventHandler(btnNameEntryOK_Click);
                    btnNameEntryOK.Margin = new Thickness(10);

                    //Place these in the order you want them to be renderd to the screen.
                    myStackPanel.Children.Add(txtNameEntry);
                    myStackPanel.Children.Add(btnNameEntryOK);
                    border.Child = myStackPanel;
                    nameEntry.Child = border;

                    //set screen position of pop up 
                    nameEntry.VerticalOffset = 100.0;
                    nameEntry.HorizontalOffset = 50.0;

                    //open pop up
                    nameEntry.IsOpen = true;

XAML:

  <phone:PhoneApplicationPage 
    x:Class="MazeEscapePhoneSilveright.GamePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    shell:SystemTray.IsVisible="False">

    <!--No XAML content is required as the page is rendered entirely with the XNA Framework-->
</phone:PhoneApplicationPage>
4

1 回答 1

1

如果由于通过using指令导入命名空间而产生歧义,那么您可以根据需要将完整的命名空间用于正确的Color对象。

我不确定您需要为代码中的成员准确使用哪一个,因为您尚未发布它,而不是仅使用Coloruse:

Microsoft.Xna.Framework.Color.YOUR_MEMBER_CALL

或者

System.Windows.Media.Color.YOUR_MEMBER_CALL

或者,您可以从文件顶部删除其中一个using Microsoft.Xna.Framework;或指令;using System.Windows.Media;以最合适的为准。您在已删除命名空间中使用的任何其他类型都必须更新以包含完整(或部分)命名空间以限定其名称。

最后一个选项是您可以指定命名空间别名。因此,例如,如果您想对 Silverlight 颜色进行特殊调用,您可以在文件顶部添加:

using SilverlightMedia = System.Windows.Media;

然后稍后在代码中您可以拥有:

var myColor = SilverlightMedia.Color.FromArgb(255, 255, 255, 255);
于 2013-06-26T13:10:00.437 回答