【问题标题】:ToggleSwitch in the WP8WP8 中的切换开关
【发布时间】:2014-07-16 10:32:53
【问题描述】:

我正在 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?)

我该如何解决?

【问题讨论】:

    标签: c# visual-studio xaml windows-phone-8


    【解决方案1】:

    如果您已经正确安装了 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"/>
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2013-01-24
        • 2021-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-01
        • 1970-01-01
        相关资源
        最近更新 更多