none
Pivotviewer Custom Actions Tooltip - facet values

    Question

  • I would like to have a tooltip appear over each item when a user moves the mouse over it. However I have read that this is not yet supported.

    As a partial solution I have added a custom action button to each item. Since the custom action button does have a tooltip value, I would like to use that to display information about the item itself.

    Is there a way to pull up the value of a specfic facet in the collection to put in place of the "tooltip" text below.

    For instance I have a facet called "Country" in the pivot data. I would like to have the tooltip below list the country for each item.

    protected override List<CustomAction> GetCustomActionsForItem(string itemId)
            {
                return (new List<CustomAction>()  
          {  
              new CustomAction("Details", new Uri("info:action1"), "tooltip", "Details1"),  
          });
            }

     

    Thanks in advance for any assistance.

    Saturday, December 04, 2010 3:45 PM

Answers

  • References you need:

    using System.Collections.Generic;
    using System.Windows.Pivot;

    You can use this: pivotItem.Facets.ContainsKey("");

    However some code like this is easy for a single facet:

    // pivotItem.Facets.TryGetValue(string key, out IList<string> value)
    string keyName = "MyFacet";
    IList<string> facetValues = new IList<string>();
    pivotItem.Facets.TryGetValue(keyName, out facetValues);

     

    Monday, December 06, 2010 3:58 AM

All replies

  • Here is a sample that accesses all the facets for the current item, CurrentItemId:

    private void btnItemInfo_Click(object sender, EventArgs e)
            {
                string facets = "facets";
                string facet = "";
                PivotItem pivotItem = PivotViewer.GetItem(PivotViewer.CurrentItemId);
                if (pivotItem != null)
                {
                    foreach (KeyValuePair<string, IList<string>> kvp in pivotItem.Facets)
                    {
                        facet = "[" + kvp.Key + "] = " + String.Join(", ", ((List<string>) kvp.Value).ToArray());
                        if (facet.Length > 40) facet = facet.Substring(0, 37) + "...";
                        facets += "\n" + facet;
                    }
                }
                else
                {
                    facets = "No item selected, please select an item first.";
                }
                ChildWindow childWin = new ChildWindow();
                childWin.Content = facets;
                childWin.Show();
            }

    This code iterates the facets of the current select item and displays them in a child window.

    You can use another item id and 'pivotItem.Facets.ContainsKey("Experts' Rating")' to check if facet value(s) exist. Note the ToArray & String.Join to concatenate multiple facet values.

    Saturday, December 04, 2010 3:56 PM
  • Thanks, that looks like its heading in the right direction. I assume the code would need to be added to the CustomPivotViewer.cs page.

    What assembly reference does that function require?

    And how could I get access to one specific facet value to display in my tooltip, rather than opening another child window?

    Sorry for my ignorance, this is my first time working with a Silverlight project in Visual Studio 2010.

    Sunday, December 05, 2010 6:08 PM
  • I found the right place to add that code and it does work. Thanks.

    I would like to pass that string 'facets' from the MainPage.xaml.cs to the CustomPivotViewer.cs page in my project that has the CustomAction and tooltip. Is that possible?

    Sunday, December 05, 2010 8:27 PM
  • You can  work with the facet values directly in the CustomAction handler. I post some code shortly.

    Monday, December 06, 2010 3:31 AM
  • References you need:

    using System.Collections.Generic;
    using System.Windows.Pivot;

    You can use this: pivotItem.Facets.ContainsKey("");

    However some code like this is easy for a single facet:

    // pivotItem.Facets.TryGetValue(string key, out IList<string> value)
    string keyName = "MyFacet";
    IList<string> facetValues = new IList<string>();
    pivotItem.Facets.TryGetValue(keyName, out facetValues);

     

    Monday, December 06, 2010 3:58 AM
  • Thanks for your reply.

    A need a reference key to get details for show on pop up, but i don't want to insert this key into facets list<>.

    Do you have any solution to pass trow its value without show it on Pivot?

     

    Thanks a lot for your attention

     

    Best Regards

    Friday, December 10, 2010 5:31 AM
  • It will be best to have it as a facet and just make it invisible to the UI:

    <FacetCategory Name="Tag" Type="String" p:IsFilterVisible="false" p:IsWordWheelVisible="false" p:IsMetaDataVisible="false" />

    That should work nicely and you can access the hidden facet in code behind.

    Friday, December 10, 2010 5:50 AM
  • Hi

    Thanks for your reply.

    My list is dymamic.

    I don't have facet on xaml....

    Friday, December 10, 2010 6:23 AM
  • Sorry, that snippet was from the CXML.

    Friday, December 10, 2010 6:31 AM
  • I've been away from this project for a bit. Thanks for posting this code. I haven't quite found the right place to insert it to make it work.

    My CustomEventHandler is in the MainPage.xaml.cs

    public void CustomActionClicked(object sender, ItemActionEventArgs e)
            {
                string facets = "facets";
                string facet = "";
                PivotItem pivotItem = PivotViewer.GetItem(PivotViewer.CurrentItemId);
                if (pivotItem != null)
                {
                    foreach (KeyValuePair<string, IList<string>> kvp in pivotItem.Facets)
                    {
                        facet = "[" + kvp.Key + "] = " + String.Join(", ", ((List<string>)kvp.Value).ToArray());
                        if (facet.Length > 40) facet = facet.Substring(0, 37) + "...";
                        facets += "\n" + facet;
                    }
                }
                else
                {
                    facets = "No item selected, please select an item first.";
                }
               
                ChildWindow childWin = new ChildWindow();
                childWin.Content = facets;
                childWin.Show();
            
            }

     

    But the toolip where I would like to display the facet values is in the CustomPivotViewer.cs :
    (You can see I currently have the string facets1 as an example of what I would like to appear in the tooltip. I'd like to replace the "Country" and "Category" with the actual facet value for each item):

    public class CustomPivotViewer : PivotViewer
        {
            string facets1 = "Properties" + Environment.NewLine + "Country" + Environment.NewLine + "Category" + Environment.NewLine + "Store";
           

            public Func<string, List<CustomAction>> GetCustomActionsForItemCallback
            {
                get;
                set;
            }

            protected override List<CustomAction> GetCustomActionsForItem(string itemId)
            {
                return (new List<CustomAction>()  
          {  
             
              new CustomAction("Details", new Uri("info:Details_click"), facets1, "Details1"), 
      });
            }

           

        }        }

    I haven't figured out how to use that code to grab the facet value in this page and make it appear in the tooltip. Please let me know how that might be possible.

     

    Wednesday, December 22, 2010 6:47 PM