Ticket T232958
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

ConditionalAppearance - How do I customize the item caption text based on a certain condition

Change Caption of property dynamically based on boolean value

created 10 years ago

I found link https://www.devexpress.com/Support/Center/Question/Details/Q535803, but I have a feeling this could be much simpler for my situation. I have a property:

public string Title
        {
            get { return _title; }
            set { SetPropertyValue("Title", ref _title , value); }
        }

And some bool:

[VisibleInListView(false)]
        [VisibleInDetailView(false)]
        public bool Switch
        {
            get { return _switch ; }
            set { SetPropertyValue("Switch", ref _switch, value); }
        }

Now if switch is true I like to present a different caption for Title. I tried using an appearance rule but this does not seem to support Caption changes.

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello Evert,

I have investigated your sample and made some modifications in the Example and AdjustMemoCaptionsViewController classes. It looks like your application works as expected now. The corrected sample is attached. Please take special note of the AdjustMemoCaptionsViewController controller, which was moved from the DynamicCaptionChanger.Module project into the DynamicCaptionChanger.Module.Web.

I hope you will find this answer helpful. Feel free to contact me if you need further assistance or have additional questions.

    Comments (2)
    EW EW
    Evert Wiesenekker 10 years ago

      Thank you very much for this foolproof example! This works

      Aleksei M. (DevExpress) 10 years ago

        You are always welcome, Evert!

        created 10 years ago

        Hello Evert,

        A similar problem was already discussed in the following thread: ConditionalAppearance - How do I customize the item caption text based on a certain condition
        I hope that this article meets your needs. If you have further questions, I will be happy to assist you.

          Comments (3)
          EW EW
          Evert Wiesenekker 10 years ago

            Based on your links it seems to be simple, solution:

            1. Create a controller
            2. Add:
                 protected override void OnViewControlsCreated()
                 {
                      base.OnViewControlsCreated();
                      SetItemCaption("Title");
                 }
                  private void SetItemCaption(string itemToFind)
                  {
                         var viewItem = ((DetailView)this.View).FindItem(itemToFind);
                         if (viewItem == null) return;
                         var someObject = viewItem.CurrentObject as SomeObject;
                         if (someObject == null) return;
                         viewItem.Caption = someObject.Switch ? "Text 1" : "Text 2";
                         View.Refresh(); //****** DOES NOT SEEM TO WORK ALWAYS
                  }
              Only problem I noticed the value is not always refreshed.
            Aleksei M. (DevExpress) 10 years ago

              Hello Evert,

              Would you please send us a small sample project with the described controller? It will help us give you more precise suggestions and provide you with correct examples.

              EW EW
              Evert Wiesenekker 10 years ago

                I have attached a project simulating the problem. On the first click of the switch the caption is not changed. After a few clicks it seems 'to warm up' and works better.

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.