User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

[Unity] UserControls, CustomControls and Behaviors

11 May 2014, 19:20

I created a few UserControls following your tutorial for Unity. I've got them working within Unity but unfortunately Visual Studio gives me build errors now.

The problem is that the class-name in the 'code-behind'-file is of course the same as the one in the xaml. Now VS tells me that I should use the partial modifier. If I do this VS complains that they must not use different base-classes, as the one in the source file inherits from Noesis.UserControl and the one in Xaml inherits from System.Windows.Controls.UserControl.

Is there any way around this problem as I find it very unfortunate not to be able to build it with VS (or Blend)?



I also saw that there is a tutorial for custom controls. So is it somehow possible to create custom controls using NoesisGUI for Unity?

I also tried to create a WPF-behavior but had trouble accessing it within xaml. Afair it was telling me that I couldn't find the behavior.


One more question for now. I was working on a draggable window. I started off creating a draggable panel and added an extension method BringToForeground() to the FrameworkElement. The next step would be to create the draggable window but I'm not sure which way to go as I don't really know what possibilities there are.

Can I inherit from a HeaderedContentControl and just overwrite its templates?

Or do I have to create another UserControl with an additional Header property? Well, I tried to go that route but I'm not allowed to register "object" as a dependency property. The problem with that is that if I'm going to support FrameworkElements (or maybe BaseComponent) only then I can't support strings any more.

I could also go the way with less flexibility and just add a title, titlebar buttons, content, etc.

So what's the best way to go? Maybe there is a completely different solution that I missed so far.
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: [Unity] UserControls, CustomControls and Behaviors

12 May 2014, 12:57

I created a few UserControls following your tutorial for Unity. I've got them working within Unity but unfortunately Visual Studio gives me build errors now.

The problem is that the class-name in the 'code-behind'-file is of course the same as the one in the xaml. Now VS tells me that I should use the partial modifier. If I do this VS complains that they must not use different base-classes, as the one in the source file inherits from Noesis.UserControl and the one in Xaml inherits from System.Windows.Controls.UserControl.

Is there any way around this problem as I find it very unfortunate not to be able to build it with VS (or Blend)?
You have to create separate code files for VS/Blend and for Unity, both systems are not compatible, although conversion from one to another is quite straightforward. For example, if you have a ColorPicker.xaml UserControl in Unity with its corresponding script ColorPicker.cs inheriting from Noesis.UserControl, you have to create in the Blend project another file named ColorPicker.xaml.cs, inheriting from System.Windows.Controls.UserControl.
I also saw that there is a tutorial for custom controls. So is it somehow possible to create custom controls using NoesisGUI for Unity?
The creation of custom controls in Unity is very limited, because we are not exposing base class virtual methods to the Unity API. So it would be very tricky to get them working as desired.
I also tried to create a WPF-behavior but had trouble accessing it within xaml. Afair it was telling me that I couldn't find the behavior.
Behaviors and all the Interactivity objects are not implemented. We have plans of incorporating them to improve MVVM capabilities.
One more question for now. I was working on a draggable window. I started off creating a draggable panel and added an extension method BringToForeground() to the FrameworkElement. The next step would be to create the draggable window but I'm not sure which way to go as I don't really know what possibilities there are.

Can I inherit from a HeaderedContentControl and just overwrite its templates?

Or do I have to create another UserControl with an additional Header property? Well, I tried to go that route but I'm not allowed to register "object" as a dependency property. The problem with that is that if I'm going to support FrameworkElements (or maybe BaseComponent) only then I can't support strings any more.

I could also go the way with less flexibility and just add a title, titlebar buttons, content, etc.

So what's the best way to go? Maybe there is a completely different solution that I missed so far.
As I explained before, custom controls are not very useful now, so I will go for the UserControl. If you want to include a Title property, you can always create a simple TextBlock to wrap the string title, so the property can perfectly be of FrameworkElement type.
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] UserControls, CustomControls and Behaviors

12 May 2014, 23:32

Thanks a lot, your suggestion solved my building problems within VS. :)

Now I've another question regarding ContentPresenter. For my draggable window I tried to create a content presenter where I define a default template but that can also be overwritten. The trouble is that it just doesn't display the content of the template so I'm stuck again. :(

Just to be sure I also created a WPF project and tried it there and it worked as expected. Is there a chance to create a UserControl that I can use similar to a HeaderedContentControl? Or is the only way to solve this to create lots of UserControls with the same code (i.e. drag code) again and again? :S
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: [Unity] UserControls, CustomControls and Behaviors

13 May 2014, 09:25

Discrepancies between WPF and NoesisGUI are not desirable, it should behave the same.
So, could you please create a ticket in our bugtracker and attach the sample files necessary to reproduce this scenario?
Thanks in advance.

Who is online

Users browsing this forum: No registered users and 0 guests