golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

[Unity] How to set HeaderedContentControl header with string

13 Sep 2014, 11:07

Hi all,

I'm trying to set a expander's (which has custom controltemplate) header to string but SetHeader method only accepts basecomponent as argument. How am I going to do that?

Thanks
 
User avatar
sfernandez
Site Admin
Posts: 3188
Joined: 22 Dec 2011, 19:20

Re: [Unity] How to set HeaderedContentControl header with st

15 Sep 2014, 16:23

The API is not correct, we will fix it in the next release.

Meanwhile, there is a tricky way to do it, by using other property that allows to set a string like the FrameworkElement.Tag property:
expander.SetTag("myHeader");
expander.SetHeader(expander.GetTag());
Sorry for the inconvenience :(
 
golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

Re: [Unity] How to set HeaderedContentControl header with st

15 Sep 2014, 20:25

Your tricky way is worked but I'm using tag property for another purpose so I tried creating new class which inherits from BaseComponent and override ToString method, it don't work. What am I missing?
 
User avatar
sfernandez
Site Admin
Posts: 3188
Joined: 22 Dec 2011, 19:20

Re: [Unity] How to set HeaderedContentControl header with st

16 Sep 2014, 09:35

You can still use Tag for whatever you want. My workaround only needs the Tag property to construct a BaseComponent object with a boxed string inside.

You can save the current Tag and restore it later:
Noesis.BaseComponent tag = expander.GetTag();
expander.SetTag("myHeader");
expander.SetHeader(expander.GetTag());
expander.SetTag(tag);
Or you can use a helper object just to construct this boxed strings:
_helperElement = new FrameworkElement();
//...
_helperElement.SetTag("myHeader");
expander.SetHeader(_helperElement.GetTag());

But remember that this is only a workaround until we fix the SetHeader to set a string.
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] How to set HeaderedContentControl header with st

18 Sep 2014, 07:12

Are you sure it's a good idea to change SetHeader to take a string? I may be wrong but I think the Header of the HeaderedContentControl in WPF is of type object so it's possible to pass even more complex objects in there.

And I guess certain things would become more difficult because it would probably prevent specifying a more complex header within XAML. But again, it may also be wrong here. :)

The same problem with base component also applies to various other cases. So the main problem is that you often need the base component instead of just an object which makes certain things just a bit more cumbersome than they would need to be.

Oh, also the lack of support of generics is occasionally really frustrating. :P
 
User avatar
jsantos
Site Admin
Posts: 4186
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] How to set HeaderedContentControl header with st

18 Sep 2014, 11:43

But remember that this is only a workaround until we fix the SetHeader to set a string.
Also please, remember to file a bug to track this.
 
User avatar
jsantos
Site Admin
Posts: 4186
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] How to set HeaderedContentControl header with st

18 Sep 2014, 11:47

Are you sure it's a good idea to change SetHeader to take a string? I may be wrong but I think the Header of the HeaderedContentControl in WPF is of type object so it's possible to pass even more complex objects in there.

And I guess certain things would become more difficult because it would probably prevent specifying a more complex header within XAML. But again, it may also be wrong here. :)

The same problem with base component also applies to various other cases. So the main problem is that you often need the base component instead of just an object which makes certain things just a bit more cumbersome than they would need to be.
It is a workaround for the v1.1, overloading the function with both BaseComponent and String.

But all this, won't be needed in v1.2 because we have fixed the architecture to support native objects everywhere. This way our API will be more similar to WPF.
Oh, also the lack of support of generics is occasionally really frustrating. :P
Collections are also being fixed in v1.2. Is this what you mean or a different thing?
 
User avatar
sfernandez
Site Admin
Posts: 3188
Joined: 22 Dec 2011, 19:20

Re: [Unity] How to set HeaderedContentControl header with st

18 Sep 2014, 11:50

Are you sure it's a good idea to change SetHeader to take a string? I may be wrong but I think the Header of the HeaderedContentControl in WPF is of type object so it's possible to pass even more complex objects in there.

And I guess certain things would become more difficult because it would probably prevent specifying a more complex header within XAML. But again, it may also be wrong here. :)
I didn't explain it correctly. Our intention is to provide two versions of the SetHeader function (for 1.1.12 version), as it occurs with other BaseComponent properties (like Tag). You will be able to call SetHeader("Some header") or SetHeader(headerElement) being headerElement any BaseComponent derived object.
The same problem with base component also applies to various other cases. So the main problem is that you often need the base component instead of just an object which makes certain things just a bit more cumbersome than they would need to be.

Oh, also the lack of support of generics is occasionally really frustrating. :P
Upcoming 1.2 version will deal with these problems better. We are working to provide an API equivalent to WPF, exposing properties instead of functions, 'object' instead of 'BaseComponent' type, etc.
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] How to set HeaderedContentControl header with st

18 Sep 2014, 22:36

I'm glad you're just overloading the method. :)

And it sounds very promising that we'll be able to use any object instead of just from BaseComponent derived classes.
Oh, also the lack of support of generics is occasionally really frustrating. :P
Collections are also being fixed in v1.2. Is this what you mean or a different thing?
Collections are just one issue. The other one is that right now it's not possible to create a generic class, add the "Extended"-attribute and just use it in Noesis.
 
User avatar
jsantos
Site Admin
Posts: 4186
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] How to set HeaderedContentControl header with st

19 Sep 2014, 03:10

Collections are just one issue. The other one is that right now it's not possible to create a generic class, add the "Extended"-attribute and just use it in Noesis.
The "Extended" attribute is going to be deprecated in v1.2 also. So, I think that Generic classes should work fine also.

Who is online

Users browsing this forum: Google [Bot] and 1 guest