2014-07-16 37 views
0

我正在编写VS2013中的WP8应用程序,并且我想将ToggleSwitch添加到我的移动应用程序中。为了实现这一点,我点击了我的项目上的“管理NuGet软件包”(最新版本),并选择了Windows Phone Toolkit。我有以下XAML代码:WP8中的ToggleSwitch

xmlns:tool="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
<ToggleSwitch x:Name="toggleSwitch1" Header="ToggleSwitch" 
       OnContent="On" OffContent="Off" 
       Toggled="ToggleSwitch_Toggled"/> 

,并且错误是: 1)The tag 'ToggleSwitch' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. 2)The name "ToggleSwitch" does not exist in the namespace "http://schemas.microsoft.com/client/2007".

另外,WP页面上使用的语句using Microsoft.Phone.Controls.Toolkit;以下得到一个错误:The type or namespace name 'Toolkit' does not exist in the namespace 'Microsoft.Phone.Controls' (are you missing an assembly reference?)

我该如何解决它?

回答

3

如果您已经正确安装了Nuget Package,那么下面的代码应该完美运行。

 xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
     <toolkit:ToggleSwitch x:Name="ToggleSwitch" Header="Toggle Switch" IsChecked="false" Content="Content Goes here" Checked="switch_Checked" Unchecked="switch_Unchecked"/> 
1

您需要在您的元素调用中使用您的名称空间标识符作为前缀。像这样

<tool:ToggleSwitch x:Name="toggleSwitch1" Header="ToggleSwitch" 
      OnContent="On" OffContent="Off" 
      Toggled="ToggleSwitch_Toggled"/> 

这应该可以解决您的问题。