我试图做的是使用silverlight在xna中创建一个弹出窗口,但是它引发了一个错误,说“system.windows.media.color”和“Microsoft.xna.framework”的引用存在歧义。颜色',有没有解决方案......如果有的话,任何建议都会非常有用。
编辑:
确定那已经奏效了,但我现在又遇到了另一个问题,即将出现一个错误,即'元素已经是另一个元素的孩子了'......任何人都可以帮助我吗?当它到达'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>
答案 0 :(得分:1)
如果由于通过using
指令导入名称空间而导致歧义,那么您可以根据需要使用完整的名称空间来填充正确的Color
对象。
我不确定您需要在代码中使用哪一个,因为您还没有发布它,而是仅使用Color
使用:
Microsoft.Xna.Framework.Color.YOUR_MEMBER_CALL
或
System.Windows.Media.Color.YOUR_MEMBER_CALL
或者,您可以从文件顶部删除using Microsoft.Xna.Framework;
或using System.Windows.Media;
指令;以最合适的为准。您在已删除的命名空间中使用的任何其他类型都必须进行更新,以包含完整(或部分)命名空间以限定其名称。
最后一个选项是您可以指定namespace alias。例如,如果您想要对Silverlight颜色进行特殊调用,可以将其添加到文件的顶部:
using SilverlightMedia = System.Windows.Media;
然后在代码中稍后您可以:
var myColor = SilverlightMedia.Color.FromArgb(255, 255, 255, 255);