[英]ToggleSwitch in the WP8
我正在VS2013中编写WP8应用程序,并且要将ToggleSwitch
添加到我的移动应用程序中。 为此,我在项目上单击“管理NuGet软件包”(已安装最新版本),然后选择Windows Phone Toolkit
。 我有以下XAML代码:
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语句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?)
我该如何解决?
如果您正确安装了Nuget软件包,则以下代码应完美运行。
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"/>
您需要使用名称空间标识符作为元素调用中的前缀。 像这样
<tool:ToggleSwitch x:Name="toggleSwitch1" Header="ToggleSwitch"
OnContent="On" OffContent="Off"
Toggled="ToggleSwitch_Toggled"/>
那应该解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.