I'm wondering if it is possible to find classes that have an attribute that is on the partial class implementation? Such that:
public class Test {
}
[Attribute()]
public partial class Test {
}
I cannot put the attribute on the original class because it is a Form.
Related
I've got the error "The Tag "EntityView.MainContent" does not exist in the "clr-namespace:Lvt.Views"."
I want to inherit from a generic base class like the following.
C#-Code:
public class EntityView<T> : UserControl where T :IEntityViewModel
{
// Property with set and get a Dependency Property
public object MainContent {get {...} set{...}
}
XAML-Code:
<local:EntityView x:TypeArguments="viewModels:EntityViewModel" x:Class="Lvt.Views.SpecialEntityView"
<local:EntityView.MainContent>
<Grid></Grid>
</local:EntityView.MainContent>
</local:EntityView>
XAML-CodeBehind:
public partial class SpecialEntityView : EntityView<EntityViewModel>
{
public SpecialEntityView() { InitializeComponent(); }
}
Does anyone know why this error message is displayed?
Thanks, Alex
I am trying to construct a validating textbox control using a generic abstract base class as follows and register Min and Max value properites:
public abstract class ValidatingTextBoxBase<T, C>
: TextBox where T : Icomparable<T>
public static readonly DependencyProperty MinValueProperty =
DependencyProperty.Register("MinValue", typeof(T), typeof(C),
new FrameworkPropertyMetadata(DefaultMinValue));
public T MinValue
{
get { return (T)GetValue(MinValueProperty); }
set { SetValue(MinValueProperty, value); }
}
Then I declare several text box controls:
public class IntegerTextBox : ValidatingTextBoxBase<int, IntegerTextBox>
{
public class DecimalTextBox : ValidatingTextBoxBase<decimal, DecimalTextBox>
{
At runtime this works great however I get a lot of design time errors for
'MinValue' property was already registered by 'DecimalTextBox'
or it will be IntegerTextBox or one of the others depending on which view is open.
Any thoughts/help would be appreciated.
My custom class for the items looks like:
public class CustomLongListMultiSelectorItem : LongListMultiSelectorItem
{
public CustomLongListMultiSelectorItem()
: base()
{
}
// other implementations...
}
Where can I allocate this item-class to the LongListMultiSelector?
I'm studying MEF, and try to use Export attribute to export a property, and import it in an other class.
But my problem is that I want to change this property and the other class can import a new value.
For example,
[Export]
public class A{
[Import("Notes")]
public string Description{get;set;}
}
[Export]
public class B{
[Export("Notes")]
public string Text{get;set;}
}
I want once I change the Text of class B, the A.Description can get changed too.
So, how can I implement this?
Any good idea?
This approach would work for most reference type but not with string which is immutable. This means that after you change the value of B.Text, the objects referenced by A.Description and B.Text will no longer be the same (you can use Object.ReferenceEquals to test this).
One way to do what you are after using MEF is to export/import a method instead of the property:
[Export]
public class A
{
public string Description { get { return GetDescription(); } }
[Import("GetNotes")]
Func<string> GetDescription;
}
[Export]
public class B
{
public string Text { get; set; }
[Export("GetNotes")]
string GetText()
{
return Text;
}
}
Finally note that there are other ways to do this. The most common in .NET is with events.
I am currently using RIA services with an object containing a child containing itself a child and it's not working :-( !
I have an update method for the BaseObject and the FirstChild are correctly present in the client but it behaves as if I have no SecondChild object (the type is not event created on the client)...
Here are the classes:
[MetadataType(typeof(BaseObjectMetaData))]
public partial class BaseObject
{
internal class BaseObjectMetaData
{
[Include, Composition]
EntityCollection<FirstChild> FirstChilds { get; set; }
}
}
[MetadataType(typeof(FirstChildMetaData))]
public partial class FirstChild:
{
internal class FirstChildMetaData
{
[Include, Composition]
EntityCollection<SencondChild> SecondChilds { get; set; }
}
}
You need to also attribute your Collection property with the AssociationAttribute as well as include a ForeignKey on your entity class and reference it in the attributes ctor arguments, remember to include the DataMemberAttribute as well (entity framework already does this by default on generated members)
heres an article outlining it further