Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF Control Properties in XAML [modified]

WPF Control Properties in XAML [modified]

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpdesignannouncement
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thrakazog
    wrote on last edited by
    #1

    I'm building my own WPF control. Once added to a Window in design mode the control needs to set some of its properties dynamically based on the Window. In code behind I'm doing this: Foo = "Some dynamic Value"; So I don't loose the new value I want the XAML updated to: < providercontrol x:name="Control1" foo="Some dynamic Value" > Much to my dismay the XAML isn't updating. So far my attempts at this will update the property value in the Properties window but the XAML remains unchanged. Without saving my change to the XAML the value is lost when the Window is closed. How can I change a property inside the control and have the XAML reflect that?

    modified on Tuesday, July 22, 2008 7:18 PM

    J T 2 Replies Last reply
    0
    • T thrakazog

      I'm building my own WPF control. Once added to a Window in design mode the control needs to set some of its properties dynamically based on the Window. In code behind I'm doing this: Foo = "Some dynamic Value"; So I don't loose the new value I want the XAML updated to: < providercontrol x:name="Control1" foo="Some dynamic Value" > Much to my dismay the XAML isn't updating. So far my attempts at this will update the property value in the Properties window but the XAML remains unchanged. Without saving my change to the XAML the value is lost when the Window is closed. How can I change a property inside the control and have the XAML reflect that?

      modified on Tuesday, July 22, 2008 7:18 PM

      J Offline
      J Offline
      Jammer 0
      wrote on last edited by
      #2

      I'm a bit confused by your question. What exactly are you expecting to see changed in the XAML?

      Jammer Going where everyone here has gone before! :) My Blog

      T 1 Reply Last reply
      0
      • J Jammer 0

        I'm a bit confused by your question. What exactly are you expecting to see changed in the XAML?

        Jammer Going where everyone here has gone before! :) My Blog

        T Offline
        T Offline
        thrakazog
        wrote on last edited by
        #3

        If I change a property from it's default I expect that change to be reflected in the XAML. Currently it is not. I change a property on the control and the XAML the doesn't change at all. I want to see the XAML updated just the same as if I updated a property on the control using the Properties window.

        J 1 Reply Last reply
        0
        • T thrakazog

          If I change a property from it's default I expect that change to be reflected in the XAML. Currently it is not. I change a property on the control and the XAML the doesn't change at all. I want to see the XAML updated just the same as if I updated a property on the control using the Properties window.

          J Offline
          J Offline
          Jammer 0
          wrote on last edited by
          #4

          Which properties window? Visual Studio? Expression Blend? Which properties are you changing? What control are you working with?

          Jammer Going where everyone here has gone before! :) My Blog

          T 1 Reply Last reply
          0
          • J Jammer 0

            Which properties window? Visual Studio? Expression Blend? Which properties are you changing? What control are you working with?

            Jammer Going where everyone here has gone before! :) My Blog

            T Offline
            T Offline
            thrakazog
            wrote on last edited by
            #5

            Sorry, I'm working with Visual Studio. I'm writing my own User control. While that control is running in design time it's going to collect some information such as its parent window code file location. So once the control is placed on the window it is going to fill in my custom string property ParentWindowPath. Once my property ParentWindowPath changes from its default, that new value should show up in the XAML. However, the XAML never sees the change. Now if I select my control on the designer, the Visual Studio Properties window does display the new value. From this know my property is being correctly set.

            J 1 Reply Last reply
            0
            • T thrakazog

              Sorry, I'm working with Visual Studio. I'm writing my own User control. While that control is running in design time it's going to collect some information such as its parent window code file location. So once the control is placed on the window it is going to fill in my custom string property ParentWindowPath. Once my property ParentWindowPath changes from its default, that new value should show up in the XAML. However, the XAML never sees the change. Now if I select my control on the designer, the Visual Studio Properties window does display the new value. From this know my property is being correctly set.

              J Offline
              J Offline
              Jammer 0
              wrote on last edited by
              #6

              I've never seen XAML 'change' ... irrespective of what properties I set in C# ... Are you expecting to see something like MyCustomPropertyName="" become MyCustomPropertyName="C:\windowlocation\window.xaml.cs" in your XAML file?? Have a read of this: http://msdn.microsoft.com/en-us/library/ms753197.aspx[^]

              Jammer Going where everyone here has gone before! :) My Blog

              T 1 Reply Last reply
              0
              • J Jammer 0

                I've never seen XAML 'change' ... irrespective of what properties I set in C# ... Are you expecting to see something like MyCustomPropertyName="" become MyCustomPropertyName="C:\windowlocation\window.xaml.cs" in your XAML file?? Have a read of this: http://msdn.microsoft.com/en-us/library/ms753197.aspx[^]

                Jammer Going where everyone here has gone before! :) My Blog

                T Offline
                T Offline
                thrakazog
                wrote on last edited by
                #7

                Jammer wrote:

                Are you expecting to see something like MyCustomPropertyName="" become MyCustomPropertyName="C:\windowlocation\window.xaml.cs" in your XAML file??

                Yep, that's exactly what I'm shooting for. It's also exactly the behavior I see if I change MyCustomPropertyName="" to MyCustomPropertyName="C:\windowlocation\window.xaml.cs" using the Properties window. Since my changes in c# show up in the Properties window I expected them to show up in the XAML as well.

                C J 2 Replies Last reply
                0
                • T thrakazog

                  Jammer wrote:

                  Are you expecting to see something like MyCustomPropertyName="" become MyCustomPropertyName="C:\windowlocation\window.xaml.cs" in your XAML file??

                  Yep, that's exactly what I'm shooting for. It's also exactly the behavior I see if I change MyCustomPropertyName="" to MyCustomPropertyName="C:\windowlocation\window.xaml.cs" using the Properties window. Since my changes in c# show up in the Properties window I expected them to show up in the XAML as well.

                  C Offline
                  C Offline
                  chester
                  wrote on last edited by
                  #8

                  I'm not sure I understand this. You're trying to use a computer to record some sort of value for you? and this virtual studio ZHAMEL that you make refernce to, this contains properties and values vis a vis teh interwebs? I have additional questions for you in order for me to help you. I should mention that I've never seen a computer do this before.

                  T 1 Reply Last reply
                  0
                  • C chester

                    I'm not sure I understand this. You're trying to use a computer to record some sort of value for you? and this virtual studio ZHAMEL that you make refernce to, this contains properties and values vis a vis teh interwebs? I have additional questions for you in order for me to help you. I should mention that I've never seen a computer do this before.

                    T Offline
                    T Offline
                    thrakazog
                    wrote on last edited by
                    #9

                    Hi there Mr. Mountain........ I've got a thread flying straight toward you......

                    C 1 Reply Last reply
                    0
                    • T thrakazog

                      Hi there Mr. Mountain........ I've got a thread flying straight toward you......

                      C Offline
                      C Offline
                      chester
                      wrote on last edited by
                      #10

                      Please do be considering to review teh interwebs for solutions twice best again: http://www.the-gog.org/twat.jpg[^]

                      1 Reply Last reply
                      0
                      • T thrakazog

                        Jammer wrote:

                        Are you expecting to see something like MyCustomPropertyName="" become MyCustomPropertyName="C:\windowlocation\window.xaml.cs" in your XAML file??

                        Yep, that's exactly what I'm shooting for. It's also exactly the behavior I see if I change MyCustomPropertyName="" to MyCustomPropertyName="C:\windowlocation\window.xaml.cs" using the Properties window. Since my changes in c# show up in the Properties window I expected them to show up in the XAML as well.

                        J Offline
                        J Offline
                        Jammer 0
                        wrote on last edited by
                        #11

                        XAML doesn't do this ...

                        Jammer Going where everyone here has gone before! :) My Blog

                        1 Reply Last reply
                        0
                        • T thrakazog

                          I'm building my own WPF control. Once added to a Window in design mode the control needs to set some of its properties dynamically based on the Window. In code behind I'm doing this: Foo = "Some dynamic Value"; So I don't loose the new value I want the XAML updated to: < providercontrol x:name="Control1" foo="Some dynamic Value" > Much to my dismay the XAML isn't updating. So far my attempts at this will update the property value in the Properties window but the XAML remains unchanged. Without saving my change to the XAML the value is lost when the Window is closed. How can I change a property inside the control and have the XAML reflect that?

                          modified on Tuesday, July 22, 2008 7:18 PM

                          T Offline
                          T Offline
                          thrakazog
                          wrote on last edited by
                          #12

                          To have your C# code change XAML properties at design time you need to create a separate DLL that talks specifically to the designer for your control. This DLL needs to be named [control name].VisualStudio.Design.Dll and deployed wherever your control.dll is. Example:

                          internal class Metadata : IRegisterMetadata {
                          
                              // Called to register design time metadata
                              public void Register() {
                                  AttributeTableBuilder builder = new AttributeTableBuilder();
                          
                                  //Task
                                  builder.AddCustomAttributes(typeof(Button), new FeatureAttribute(typeof(TaskProvider)));
                                  
                                  MetadataStore.AddAttributeTable(builder.CreateTable());
                              }
                          }
                          

                          // class that will change the property
                          class TaskProvider : Microsoft.Windows.Design.Interaction.PrimarySelectionTaskProvider
                          {
                          public TaskProvider()
                          {

                              }
                          
                              protected override void Activate(Microsoft.Windows.Design.Model.ModelItem item)
                              {
                          
                                 if (String.IsNullOrEmpty((String)item.Properties\["StringProperty"\].ComputedValue))
                                      item.Properties\["StringProperty"\].SetValue(Guid.NewGuid().ToString()); //sets the value in XAML
                          
                                  base.Activate(item);
                              }
                          }
                          
                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups