WPF Control Properties in XAML [modified]
-
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
-
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
-
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
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.
-
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.
-
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
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.
-
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.
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
-
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
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.
-
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.
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.
-
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.
-
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.
-
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
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); } }