简体   繁体   English

功能区框架的最新项目中的“ EnablePinning”属性在哪里?

[英]Where is the 'EnablePinning' property in the ribbon framework's recent items?

The Windows ribbon framework markup supports an EnablePinning attribute for the recent items menu in the application menu: Windows功能区框架标记为应用程序菜单中的“最新项目”菜单支持EnablePinning属性:

<ApplicationMenu.RecentItems>
  <RecentItems CommandName="MRU" EnablePinning="true" />
</ApplicationMenu.RecentItems>

I expected that there would be a matching property that can be queried/updated at runtime, but I can't find a property key. 我期望会有一个匹配的属性可以在运行时查询/更新,但是我找不到属性键。 Does anyone know if there is one, and, if so, what it is? 有谁知道是否有一个,如果有,那是什么?

Alternatively, is there another way to turn pinning on/off at runtime? 另外,还有另一种方法可以在运行时打开/关闭固定吗? Neither the element nor its parent support application modes. 元素或其父级都不支持应用程序模式。

TIA TIA

Clarification: What I'm trying to do is enable/disable pinning for the entire menu at runtime. 澄清:我想做的是在运行时启用/禁用整个菜单的固定。 I'm not concerned about the pin states of the individual items. 我不关心单个项目的固定状态。

I'm not sure if you can modify the pinned state from existing entries but it's definitely possible to programmatically query the state and add new items with a specific state using the UI_PKEY_Pinned property: https://msdn.microsoft.com/en-us/library/windows/desktop/dd940401(v=vs.85).aspx 我不确定是否可以从现有条目中修改固定状态,但是绝对可以通过UI_PKEY_Pinned属性以编程方式查询该状态并添加具有特定状态的新项目: https ://msdn.microsoft.com/zh-cn /library/windows/desktop/dd940401(v=vs.85).aspx

Wrappers such as the Windows Ribbon Framework for Delphi or the Windows Ribbon for WinForms (.NET) provide an easy access to the API model. 包装程序(例如DelphiWindows Ribbon框架WinFormsWindows Ribbon (.NET))可轻松访问API模型。 This CodeProject article also describes how to query/add recent items using C#. 此CodeProject文章还介绍了如何使用C#查询/添加最近的项目。

If you want to change the state during runtime, you could for example query the state of all items, remove them from the list, adjust whetever you need and add them to the list again. 如果要在运行时更改状态,则可以查询所有项目的状态,将它们从列表中删除,根据需要进行调整,然后再次将它们添加到列表中。 Didn't do that yet, could be worth a try however. 尚未这样做,但是值得一试。

Hmm... this will be quite difficult to accomplish as the flag is defined in the XML which will be compiled into a resource file that is linked to the application and then loaded on start up. 嗯,这将很难完成,因为在XML中定义了该标志,该标志将被编译成一个资源文件,该文件链接到应用程序,然后在启动时加载。 You could create another resource definition and reload the ribbon if you want to disable/enable the flagging, but that's quite a lot overhead and certainly noticeable from an users perspective as it requires the creation of a new window handle. 如果要禁用/启用标记,则可以创建另一个资源定义并重新加载功能区,但这会产生很多开销,并且从用户的角度来看当然很明显,因为它需要创建新的窗口句柄。

I place the recent items by inside UpdateProperty 我将最近的项目放在UpdateProperty中

  TRecentItem = class(TInterfacedObject, IUISimplePropertySet)
    private
      FRecentFile: TSSettings.TRecentFile;
    protected
      function GetValue(const key: TUIPropertyKey; out value: TPropVariant): HRESULT; stdcall;
    public
      procedure Initialize(const RecentFile: TSSettings.TRecentFile); safecall;
    end;

function TMyForm.UpdateProperty(commandId: UInt32; const key: TUIPropertyKey;
  currentValue: PPropVariant; out newValue: TPropVariant): HRESULT;
var
  I: Integer;
  psa: PSafeArray;
  pv: Pointer;
  RecentItem: TRecentItem;
begin
  if (key = UI_PKEY_RecentItems) then
  begin
    psa := SafeArrayCreateVector(VT_UNKNOWN, 0, Settings.RecentFiles.Count);

    if (not Assigned(psa)) then
      Result := E_FAIL
    else
    begin
      for I := 0 to Settings.RecentFiles.Count - 1 do
      begin
        RecentItem := TRecentItem.NewInstance() as TRecentItem;
        RecentItem.Initialize(Settings.RecentFiles[I]);
        pv := Pointer(IUnknown(RecentItem));
        Check(SafeArrayPutElement(psa, I, pv^));
      end;

      Result := UIInitPropertyFromIUnknownArray(UI_PKEY_RecentItems, psa, PropVar);

      SafeArrayDestroy(psa);
    end;
  end;

If a pin was changed, I get this command while closing the application menu: 如果更改了引脚,则在关闭应用程序菜单时会收到以下命令:

function TMyForm.Execute(commandId: UInt32; verb: _UIExecutionVerb;
  key: PUIPropertyKey; currentValue: PPropVariant;
  commandExecutionProperties: IUISimplePropertySet): HRESULT; stdcall;
var
  Count: Integer;
  I: Integer;
  Pinned: Boolean;
  psa: PSafeArray;
  pv: IUnknown;
  RecentFile: UInt32;
  SimplePropertySet: IUISimplePropertySet;
  Value: TPropVariant;
begin
  if ((commandId = cmdAppRecentItems)
    and Assigned(key) and (key^ = UI_PKEY_RecentItems)
    and Assigned(currentValue) and (currentValue^.vt = VT_ARRAY + VT_UNKNOWN)) then
  begin
    psa := nil;
    Result := UIPropertyToIUnknownArrayAlloc(key^, currentValue^, psa);
    if (Succeeded(Result)) then
    begin
      Result := SafeArrayGetUBound(psa, 1, Count);
      for I := 0 to Count do
        if (Succeeded(Result)) then
        begin
          Result := SafeArrayGetElement(psa, I, pv);
          if (Succeeded(Result) and Assigned(pv)) then
          begin
            Result := pv.QueryInterface(IUISimplePropertySet, SimplePropertySet);
            if (Succeeded(Result)) then
              Result := SimplePropertySet.GetValue(UI_PKEY_Pinned, Value);
            if (Succeeded(Result)) then
              Result := UIPropertyToBoolean(UI_PKEY_Pinned, Value, Pinned);
            if (Succeeded(Result)) then
              Settings.RecentFiles.SetPinned(I, Pinned);
          end;
        end;
      SafeArrayDestroy(psa);
    end;
  end
end;

... but I didn't find a documentation of this solution. ...但是我没有找到该解决方案的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM