none
Force update of custom categoryeditor RRS feed

  • Question

  • Hello,

    I have the following problem: I have some controls which have two dependencyproperties which are somehow connected. When one property has an value the other have null (which property gets the value is a bit complicated so I don't mention it).

    For achieving this I have written a custom categoryeditor, which uses an usercontrol to do this. This usercontrol is added dynamicaly as often as the above mentioned dependencyproperty pairs appears in this control. This process is made in the overriden funtion "public override bool ConsumesProperty(PropertyEntry property)". This is as far as I know the only position where I get the properties of this category (is this right?)

    This works fine. Everytime I click on a control of mine the function ConsumesProperty is called and I can collect the properties which needed to be shown in a special way. The only problem is when I switch from one of my controls to another of mine (both have different properties for showing in the category editor). Then only the ctor and the virtual function "public override string TargetCategory" getting called but not ConsumesProperty. ConsumesProperty is only called when I switch  from a control which does not have this category to a control which have this category in the designer.

    Is there a way to raise an event or something (best place for me would be in the ctor of the CategoryEditor) that would result in ComsumesProperty getting called?

    Or is there a different approach which can help me?

    Regards

    Sebastian

     

    P.S. I am using WPF and Visual Studio 2010

    Wednesday, January 12, 2011 7:43 AM

Answers

  • We know what the problem is.  The problem is that CategoryEditor.EditorTemplate is only called when an instances of the CategoryEditor does not already exists in the Property Window.  In cases where multiple Types have properties in the same category and are consumed by the same CategoryEditor, the on-the-fly DataTemplate generation will not work because an instance already exists.  If the user  selects a different Type that does not have properties in the Targeted category, the CategoryEditor is remove from the Property Window.  Thus, a new instance will be created when the user  selects a Type that has  properties in the Target category.

     

    Typically,  CategoryEditor builders layout their CategoryEditor UI once in a ResourceDictionary and then use that DataTemplate.  The DataTemplate leverages Binding techniques to set values, display names and etc.  We have attached an updated version of the project shared that leverage this method.  We have highlighted the code changes within “#region” sections.

     

    Hopefully this approach will work for you.


    bill boyce
    Monday, February 7, 2011 11:08 PM
    Moderator
  • Sent the attachment to you
    bill boyce
    • Marked as answer by Sebastian S Friday, February 11, 2011 4:44 PM
    Wednesday, February 9, 2011 8:02 PM
    Moderator

All replies

  • Hello Sebastian,

     

    Thank you for your question.

     

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

     

    Thank you for your understanding and support.

     

    Best Regards,

    Ziwei Chen


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 14, 2011 9:43 AM
  • Thank you for your help. I am looking forward for your answer. I still have not a clue how to solve this problem.

     

    Regards

    Sebastian

    Friday, January 14, 2011 2:40 PM
  • No ideas anyone? I don't believe that I am the only one confronted with this problem.

     

    Regards

    Monday, January 24, 2011 11:59 AM
  • Unfortunately, we need more information.  Specifically, do you wish to have one category editor to appear for two different categories? 

     

    Also, would it be possible to get a small mock-up sample, from you, to demonstrate what you are trying to accomplish?

     

    Thanks


    bill boyce
    Friday, January 28, 2011 5:39 PM
    Moderator
  • Hello,

    I have created a small mock-up example - in real its a "bit" more complex ;)

     

    • One project called controls which contains two controls and a new attribute called MyAttribute
    • The design project coolects dynamically all MyAttributes and uses a usercontrol for editing them.
    • The example project shows my problem. Everytime I switch from "Class1" to "Class2" the designer wont update the "My" Category part. It is only updated when I switch to a control with no "My" Category.

     

    Now I need a solution to update the category with every class switch.

     

    I think that you will clearly see my problem when you look at the example:

    Thanks!

    • Edited by Sebastian S Thursday, February 17, 2011 6:54 PM
    Saturday, January 29, 2011 3:05 PM
  • Hi,

     

    If you go between Class1 and Class2 the designer doesn’t update your category.  That still leaves a lot of guess work as to how to reproduce this.  I’m not sure if what I’m seeing is what you are talking about or is expected (I don’t see it updated regardless of what I click (class2 or the textbox). 

     

    We need very clear repro steps. C

    Can we have specific repro steps including expected behaviors?  Example – I do step 3 and it does x when I expect it to do y.

    Thanks


    bill boyce
    Monday, January 31, 2011 11:07 PM
    Moderator
  • Hi,

    my problem is that I want to update the Template of "My" Category when I change the focused Control in the designer (e.g. when I have selected the "Class1" item and than click on the "Class2" item). In this case the environment only calls ConsumeProprty, ctor and TargetCategory of "MyCategory" but NOT the EditorTemplate property.

    This EditorTemplate property is only called when the editor the old control does not have a "My" Category (like in my example an ordinary TextBox).

    You can see this when you debug the Design assembly and put a breakpoint to public override DataTemplate EditorTemplate.

    In other words:

     

    • I only want to have "Text" in the "My" Category when I have selected a "Class1" instance.
    • If I have selected a "Class2" instance. I want to have only "Text2" and "Text3". (like I have defined via the attributes).
    Thanks a lot for you help!

     

     

    EDIT:

    If you are wondering why I use a custom category editor. I use it because I combine two or more properties in one UserControl (as editor, like in the example "MyEditor".

    I have updated the example so you can see this functionality.  Here Class2 has three properties. The Properties with "Text3" as attribute have a special behaviour. When you write something in the Textbox of Text3 in the property window. The text will be saved in one of the two "Text3" properties dependeding on the length of the input string.

    Because of functionality which is similar to this combination functionality I have to use the Category editor. 

     

    So I have to options either to let the category editor somehow refresh or a way to combine properties in an other way. But for both ways I have no ideas.

     

    • Edited by Sebastian S Thursday, February 17, 2011 6:54 PM
    Tuesday, February 1, 2011 7:35 AM
  • Thank you for the additional information.  However, we still don’t have the exact repro steps.  Also, based on your latest description, we should be seeing the “My” category for “MyProperty” (Class1) with the text, “Text”, when selecting the Textbox in you example (A control without the “My” category) and then selecting the Class1 control again.  However, that is not the behavior we are seeing with the sample you provided.  Here are the steps we took:

     

    1.      Unzip the provided zip file.

    2.      Open CategoryExample.sln.

    3.      Rebuild the solution.  It succeeded.

    4.      Open MainWindow.xaml in the designer.

    5.      Select the Class1 control.

    6.      Go to the Properties window and select Categorize.

    7.      Find “My” category which contains “MyProperty”.

    8.      “MyProperty” does not contain any value.

    9.      Select Textbox.

    10.   Select Class1 control again.

    11.   Still “MyProperty” does not contain a value.  We’re expecting the value to be “Text” based on your description and code.

     

    Can you please provide the exact repro steps, including expected behavior, based on the sample you provided us?  That way we can ensure we’re all on the same page with the repro.

     

    Thank you!


    bill boyce
    Wednesday, February 2, 2011 10:29 PM
    Moderator
  • OK. Here are the exact repro steps.

     

    1. Open MainWindow.xaml in designer
    2. Select Class1 control
    3. Go to Properties Window and select Categorize
    4. "My" category now contains "MyProperty"
    5. Select TextBox
    6. Select Class2 Control
    7. In my first example zip file. You should see now "OtherProperty" and "OtherProperty2" in "My" category. This is correct
    8. Select Class1 Control again
    9. Now the "My" category of class1 still contains the two properties of class2 ("OtherProperty" and "OtherProperty2") and not "MyProperty". This is wrong!
    10. Select TextBox again
    11. Select Class1 Control again. Now "My" category contains the correct "MyProperty" property again.
    12. Select Class2 (directly no TextBox intermediate step).
    13. Now the "My" Category is wrong (it contains the properties of class 1).
    14. Select the TextBox again and than Class2 again. Now the properties are correct again.
    This problem is related in not calling DataTemplate EditorTemplate of MyCategory. This property is only called when I switch from one control which does not contain this category to one which contains this category.

    I hope you can now reproduce my problem.


    EDIT: IMPORTANT! I just realized. You should close all other Visual Studio instances otherwise you get a messageBox with "Could not load assembly controls.dll".  If this happens build the solution and reopen Visual Studio (but only one instance). This is related to in MetaData.cs of the Controls.Design.
    EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
    string dir = System.IO.Path.GetDirectoryName(dte.Solution.FullName) + @"\Controls\bin\debug\Controls.dll";
    Assembly asm = Assembly.LoadFrom(dir);
    Thursday, February 3, 2011 7:49 AM
  • We know what the problem is.  The problem is that CategoryEditor.EditorTemplate is only called when an instances of the CategoryEditor does not already exists in the Property Window.  In cases where multiple Types have properties in the same category and are consumed by the same CategoryEditor, the on-the-fly DataTemplate generation will not work because an instance already exists.  If the user  selects a different Type that does not have properties in the Targeted category, the CategoryEditor is remove from the Property Window.  Thus, a new instance will be created when the user  selects a Type that has  properties in the Target category.

     

    Typically,  CategoryEditor builders layout their CategoryEditor UI once in a ResourceDictionary and then use that DataTemplate.  The DataTemplate leverages Binding techniques to set values, display names and etc.  We have attached an updated version of the project shared that leverage this method.  We have highlighted the code changes within “#region” sections.

     

    Hopefully this approach will work for you.


    bill boyce
    Monday, February 7, 2011 11:08 PM
    Moderator
  • Hello bill,

    sorry to ask again. But where have you attached this updated version? I guess you have forgotten to post the link ;). Alternatively you can send it via mail at sebastiansch@ymail.com

    Thanks for your help!

    Tuesday, February 8, 2011 7:54 AM
  • Sent the attachment to you
    bill boyce
    • Marked as answer by Sebastian S Friday, February 11, 2011 4:44 PM
    Wednesday, February 9, 2011 8:02 PM
    Moderator
  • Could you please provide the code for this solution? I can't see any attachment in this thread.
    Wednesday, September 3, 2014 1:42 PM