在win8中使用c#从“开始”菜单取消绑定

在win8中使用c#从“开始”菜单取消绑定,c#,windows-8,tile,C#,Windows 8,Tile,我正在开发一个c#桌面应用程序 我们需要根据条件的数量取消绑定应用程序磁贴。这可能在应用程序生命周期的任何时候发生,而不仅仅是在安装期间 我看到了一个关于如何在CPP中取消平铺的问题。我在C#中也尝试过这样做,但没有成功 有什么帮助吗 更新: 我能够编写一个C#代码,将AppUserModel_StartOperation设置为AppUserModel_StartOperation_NOPINONINSTALL,但没有帮助:( 代码如下: private static void InstallS

我正在开发一个c#桌面应用程序

我们需要根据条件的数量取消绑定应用程序磁贴。这可能在应用程序生命周期的任何时候发生,而不仅仅是在安装期间

我看到了一个关于如何在CPP中取消平铺的问题。我在C#中也尝试过这样做,但没有成功

有什么帮助吗

更新:

我能够编写一个C#代码,将AppUserModel_StartOperation设置为AppUserModel_StartOperation_NOPINONINSTALL,但没有帮助:(

代码如下:

private static void InstallShortcut(string linkPath)
    {

        // Find the path to the current executable
        // String exePath = Process.GetCurrentProcess().MainModule.FileName;  //Path to the current exe file that is running.  C:\\...
        IShellLinkW newShortcut = (IShellLinkW)new CShellLink();

        // Create a shortcut to the exe
        ErrorHelper.VerifySucceeded(newShortcut.SetPath(targetPath));
       ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

        // Open the shortcut property store, set the AppUserModelId property
        IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;


            var APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL = new PropVariant(0);
            var StartPinOption = new PropertyKey(new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}"), 12);
            ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(StartPinOption, APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL));


            ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());


        // Commit the shortcut to disk
        IPersistFile newShortcutSave = (IPersistFile)newShortcut;

        ErrorHelper.VerifySucceeded(newShortcutSave.Save(linkPath, true));
    }

我尝试了这两种方法:删除磁贴,然后重新创建它,更改现有磁贴的参数,但没有任何效果,磁贴仍固定在“开始”菜单上。

您是在谈论主应用程序磁贴还是辅助磁贴?如果您指的是辅助磁贴,则有用于取消钉扎的示例代码。它的核心是(为了简单起见,我做了一些修改;完整代码见本文):

根据,无销安装选项应为(1)


我是通过这样做来工作的。

是你的应用程序是Windows商店应用程序还是桌面应用程序?如果前者,我不相信这是可能的,它违背了用户负责体验的口令。你看到的C++的样本是桌面应用程序。谢谢你的评论,我正在开发一个桌面应用程序。这个代码只适用于地铁。应用程序(Windows应用商店应用程序)。很抱歉,当我回复时,您尚未发表评论说您正在编写桌面应用程序:(
 // Check to see if this restaurant exists as a secondary tile and then unpin it
 string restaurantKey = this.m_ViewModel.Restaurant.Key;
 Button button = sender as Button;
 if (button != null)
 {
     if (Windows.UI.StartScreen.SecondaryTile.Exists(restaurantKey))
     {
         SecondaryTile secondaryTile = new SecondaryTile(restaurantKey);
         bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);

         if (!isUnpinned)
         {
             // Do error handling here
         }
     }
     else
     {
         // If we ever get to this point, something went wrong or the user manually 
         // removed the tile from their Start screen.  
         Debug.WriteLine(restaurantKey + " is not currently pinned.");
     }
 }
var APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL = new PropVariant(1);