How can I save changes to QAT? For example a user may add a shortcut from Ribbon to QAT? Currently, if I restart the application, the QAT will not show the added icon. How can this information be saved?
Thank you!
Unfortunately there is currently no built in method for saving the state of the QAT/Ribbon. You would need to iterate the Items collection of the QuickAccessToolbar. This collection will contain either QatPlaceholderTool instances or Separator(Tool) instances. If it is QatPlaceholderTool, you would want to serialize out the TargetId (the Id of the tool/group in the qat) and TargetType (i.e. whether it was a tool or a ribbongroup). Note, in order for this to work properly you will need to make sure that you set the Id property of each tool & ribbongroup to a unique value - otherwise the Id is just going to be a randomly generated value which will differ between runs of the application.
What if the ribbon items are being shared? It won't be possible to specify a unique Id in that case.
I'm not sure I follow. What do you mean by shared?
For example if I have the following defined as a resource<igRibbon:MenuTool x:Key="myColors" ..> ..</igRibbon:MenuTool>
and then, I try to use it in the ribbon as:
<igRibbon:XamRibbon ...>
....
<igRibbon:RibbonGroup Id="Group1"> <!-- Colors --> <StaticResource ResourceKey="myColors" /> </igRibbon:RibbonGroup>
<igRibbon:RibbonGroup Id="Group2"> <!-- Colors --> <StaticResource ResourceKey="myColors" /> </igRibbon:RibbonGroup>....</igRibbon:XamRibbon>
Now in this case, I can't use the unique id with my MenuTool or any of its components. Instead I have to repeat the whole tool declaration and this could be long and unmanageable.
Is there a better solution?
Have you actually tried using that snippet? I don't see how that example would work in WPF because an element can only have 1 visual parent. Also, the xamRibbon doesn't currently allow more than one instance of a tool with the same id - except for one in the QAT so I really don't see how you should get into a situation where this would be an issue. If the xamRibbon is changed in the future to allow duplicate keys I still don't see how it would be an issue as only 1 instance of a tool with a given id would have been allowed on the ribbon. If you're going to have what are logically the same tool and allow for them both to be in the QAT then you will need to come up with your own mechanism for identifying them and therefore for identifying them when you serialize/deserialize your qat tools.
In thinking about this further the snippet you had may work if you have x:Shared=false on it. In any case, the xamRibbon doesn't allow you to have more than 1 instance of a tool (apart from the one on the QAT) in the ribbon so you wouldn't be able to use the Id if you have what are multiple logically equivalent instances of a tool within the ribbon. I would recommend submitting a suggestion for allowing multiple instances so that when QAT tool serialization is built into the control you could take advantage of it. For now as I've said you'll probably have to come up with your own means of identifying the tools and use that when you serialize/deserialize.