簡體   English   中英

在Win8中使用C#從開始菜單取消固定

[英]Unpin from start menu using c# in win8

我正在開發ac#桌面應用程序。

我們需要根據條件數取消固定應用程序圖塊。 這可能在應用程序生命周期中的任何時候發生,而不僅是在安裝過程中。

我看到這個如何在CPP取消固定瓷磚的問題。 我也嘗試在C#中這樣做,但沒有成功。

有什么幫助嗎?

更新:

我能夠編寫一個C#代碼,將AppUserModel_StartPinOption設置為APPUSERMODEL_STARTPINOPTION_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));
    }

我都嘗試過:刪除磁貼,然后重新創建它,並更改現有磁貼的參數,但沒有任何效果,磁貼仍固定在開始菜單上。

您是在談論主應用程序磁貼還是輔助磁貼? 如果您指的是輔助磁貼,則本文提供了用於取消固定的示例代碼。 它的實質是(為了簡單起見,我在進行一些修改;有關完整代碼,請參見文章):

 // 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.");
     }
 }

根據MSDN文章:System.AppUserModel.StartPinOption(Windows) ,無引腳安裝選項應為(1)

var APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL = new PropVariant(1);

我這樣做可以使它正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM