Hi can I create instances of classes with different namespace in owl?
I have a class performance with name space="http://w3id.org/gbo/" which is different from my namespace .Can I create instances/namedIndividuals of that class?
Related
I have been binding in WPF application directly to the model classes (and skipping creating individual viewmodel classes).
Now, after switching to EF6 and DBContext, I face an issue with the generated EF POCO classes since it looks its either kind of tricky or not even recommended trying to make INotifyPropertyChanged interface implemented directly to those classes.
Currently:
I don't want to go back to ObjectContext.
I don't want to change T4 too much either. The suggestions on the web for changing T4 to achieve
INotifyPropertyChanged looks too error-prone for me.
Creating viewmodels for each class now and going purely to MVVM
would probably be best but takes now lot of time to implement since the model
is huge.
Do I have any options left to get EF6 POCO class autogenerated properties to notify of their changes?
T4 Templates are your best friends here. You almost can't avoid them
Option 1 - Modify your existing T4 templates to implement INotifyPropertyChanged
Create a base class that implements INotifyPropertyChanged
Modify the getter and setters in your T4 templates to notify of their
property changes
Option 2 - Introduce DTOs/ViewModels and use AutoMapper
Add a new folder to your project (or create another project)
Add a new POCO generation T4 template
Modify it slightly to conform to your view model of choice
Use AutoMapper to map these Dto/ViewModels to the entities
Option 3 - Implement Postsharp which uses aspect oriented programming to implement INotifyPropertyChanged with a one line attribute per class - again, you'll have to add a couple of lines to your T4 template
EDIT - examples
Here's a T4 template with my entities, that I added the [DataContract] attributes to allow the POCOs to be serialized.
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
{
fileManager.StartNewFile(entity.Name + ".cs");
BeginNamespace(code);
#>
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
using System.Runtime.Serialization;
[DataContract]
<#=codeStringGenerator.EntityClassOpening(entity)#>
{
// Then further down
var simpleProperties = typeMapper.GetSimpleProperties(entity);
if (simpleProperties.Any())
{
foreach (var edmProperty in simpleProperties)
{
#>
[DataMember]
<#=codeStringGenerator.Property(edmProperty)#>
<#
I have four UserControls in my WPF Application - e.g.
VisualA, VisualB, VisualC, VisualD
I want each of them need to inherit a generic "Player" Class which contains a heap of shared code -. e.g. methods, timers etc
So far this is what I have tried in my Control's XAML
<UserControl x:Class="VisualA"
And here is what I have in a separate Class file.
Partial Public Class VisualA
Inherits Player
End Class
Public Class Player
Inherits UserControl
End Class
In my Window, I'm referencing the UserControl as normal:
<local:VisualA></local:VisualA>
But, I'm getting the following error:
Base class 'System.Windows.Controls.UserControl' specified for class
'VisualA' cannot be different from the base class 'Player' of one of
its other partial types
What am I doing wrong?
I was also under the impression any code (i.e. methods) inside the inherited class (Player) would be able to access the Controls in the UserControl by referencing by name - is that correct?
The base class in the XAML is still set to UserControl. Change it to Player. Also note that the namespace for the Player type will have to be defined. i.e:
<BaseClasses:Player x:Class="VisualA"
xmlns:BaseClasses="clr-namespace:MyProject.BaseClasses"
... all your other namespaces used
The application that I'm building has several (10+) [Module] executables.
I would like to specify something like this in [Module]View.xaml file.
<Window ...
mef:ExportView ExpectingViewModel={x:Type [Module]ViewModel}
>
</Window>
where mef:ExportView is a MarkupExtension which prepares the parts for the MEF composer.
Currently,...
In [Module]View.xaml.cs file I mark my View with an ExportView(typeof([Module]ViewModel)) attribute inside the . (The typeof param specifies the expected ViewModel.)
I also mark my ViewModel with an [ExportViewModel] attribute.
(Both attributes derive from ExportAttribute.)
Each executable's Application class also inherits from an ApplicationBase class which does the MEF composition and marries/links the View/ViewModel.
Now, I would like to be able to remove all code-behind from the [Module]View.xaml.cs to prevent myself and my co-workers from forgetting to markup the code-behind file.
I'm thinking this would require a custom MarkupExtension. I'm familiar with the basics of MEF, as well as creating custom export attributes with metadata. However, I think this solution would require deriving from some of the MEF primitives.
I have read multiple posts on the subject but still cannot manage to make it work.
I want 2 user controls slidertype1 and slidertype2 which should inherit from slidercommontype, all are in same namespacecommon, can someone knows the syntax for this simple use case ?
Inspiring from http://jamescrisp.org/2008/05/26/wpf-control-inheritance-with-generics/
I tried:
<namespacecommon:slidercommontype x:Class="namespacecommon.slidertype1">
but I got namespacecommon:slidercommontyp doesn't exist in xml namespace.
As long as the base class doesn't have a XAML file associated with it, it's pretty easy. Trying to incorporate the visual aspect of the user control using XAML is not really a supported scenario.
Having said that, just create your class SliderCommonType (although I would call it SliderBase or something.)
namespace MyControls {
public class SliderBase : UserControl {
}
}
Then create your two controls based on it. I'll show one example and the other should be obvious.
<Local:SliderBase x:Class="MyControls.SliderType1"
xmlns:Local="clr-namespace:MyControls">
</Local:SliderBase>
And the code-behind would look like this:
namespace MyControls {
public class SliderType1 : SliderBase {
}
}
The key point being that your XAML file has to reference the base class which requires changing the <UserControl> element to <Local:SliderBase> which in turn requires a XAML namespace import.
When you add a UserControl using the default template, you can just change the code it creates to reflect the above changes. It's much easier than trying to create it from scratch.
One last thing to note - you will need your application to compile successfully before you can use the visual designer on your derived controls. This is because the designer needs to be able to instantiate SliderBase at design-time.
I want this usercontrol to be Created via MEF but also to have the usercontrol positioned and properties set on it in Blend... How can I force the composition of the imports that the usercontrol requires when I have a 'Concrete' reference to the usercontrol ?
What happended to PartsInitializer.Satisfy ?
Export for the UserControl
[Export(typeof(IWOFlyOutFilterMenuView))]
public partial class FlyoutTab_WOsViewFilter : UserControl,IWOFlyOutFilterMenuView,IPartImportsSatisfiedNotification
No Imports in the Containing view as it is a concrete instance.
Thanks
Greg
You can force the composition when you have an instance like this:
Import the namespace System.ComponentModel.Composition (to include the extension method SatisfyImportsOnce
Create a CompositionContainer
Call SatisfyImportsOnce on the composition Container and supply it the instance of the usercontrol.
Take care,
Martin