.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Accessing Generic Type in XAML

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :WPF
Hello, How can I access a Type with generic parameter in XAML. class SampleClass<T> { } now in XAML: i want to access xmlns:local="Ref to SampleClass" How it will create the instance of SampleClass<T>?

View Complete Post

More Related Resource Links

How can I access a Type with generic parameter in XAML

Hello, How can I access a Type with generic parameter in XAML. class SampleClass<T> { } now in XAML: i want to access xmlns:local="Ref to SampleClass" How it will create the instance of SampleClass<T>?

Need Syntax To Make Results of LINQ Union Return Non-Generic Type



I have the below SQL which works just fine:

SELECT     Message, CreateDate, AccountId, AlertTypeId
FROM       dbo.Alerts
SELECT     TOP (100) PERCENT Status, CreateDate, AccountId,
                          (SELECT     10 AS Expr1) AS AlertTypeId
FROM         dbo.StatusUpdates
WHERE AccountId = PassedInParameter

I have been going about trying to convert the above into a LINQ method and am having problems with return types.
As the above SQL illustrates, I am querying two distinct LINQ tables - Alerts and StatusUpdates -
and then attempting to perform a Union on them. In order to do the union in LINQ, I have to have agreeing types. So, I
am using "var" to make the results of "alerts" and "updates" generic before the union.  

public IList GetStatusUpdatesAsAlertsByAccountId<T>(Int32 accountId)
            using (WorkbookDataContext dc = _conn.GetCont

VS 2010 XAML Design View Load always fail with a Type Load Exception

Create a new WPF project in VS and change nothing. The Design View will fail to load with the error below. Error    1    Could not load type 'Microsoft.Expression.DesignModel.Core.ISharedInstanceBuilder' from assembly 'Microsoft.Expression.DesignModel, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Microsoft.Expression.DesignModel is an assembly from Expression Blend. I ever installed Blend 4 RC and uninstall and install Blend 4. I Reflector the assembly I have under Blend 4 bin folder. And cannot find a interface named ISharedInstanceBuilder. But the WPF project is a Template project without any changes. How it get related with Blend 4? And how to fix it? Thanks.  

XML databinding - accessing attributes of ParentNode from childNode in XAML

Hi All, I would like to get the ParentNode of a given childNode for the xml databinding in XAML. So what should I do ??? For instance: [XML] <Answer           Margin="40,1,1,1"           TabIndex="4"           Name="Answer"           DataType="bool"           Value="N">           <Option             Name="Y"             DisplayText="Yes"             MaxLength="1"             Width="20" />           <Option             Name="N"             DisplayText="No"             MaxLength="1"             Width="

Generic.xaml and Resources stored in App.xaml

Hi, I store things like ValueConverters or Brushes in the App.xaml, custom controls are stored in the generic.xaml. Now I'd like to get access  to those resources in the App.xaml from my custom controls in generic.xaml, but if I try to access them with {StaticResource TestConverter}, my programm seems to not find them. How can I achieve this? With ComponentResourceKeys?   Tobi  

Use a generic type parameter with a GetBody<>

I have a generic messaging system which can pass any type of message around.  I have put the type of object in the Message Header so that I know when I receive it what type I need.  Is there any way to take the string that contains the name of the type and use that in the MessageReceived.GetBody<>. It would be nnice to be able to do that instead of a messy if else checking the string to know message types and then hard coding the Type in the GetBody.   Thanks in advance    needbrew

Binding a custom type in XAML ?

Hi, I'd like to bind a property "myProperty" of type "MyType" in the text property of TextBlock : <TextBlock Text="{Binding myProperty, Mode=OneWay}" And I overrided the ctype operator to have conversion from "MyType" to String: Public Overloads Shared Narrowing Operator CType(ByVal v As MyType) As String ...................... End Operator But it seems not work! I get the ToString of "MyType" in result but not the return of CType operator. Is it normal ? Why ?   Thanks for your help.  

Cannot create unknown type when loading WF Service from loose Xaml with ActivityXamlServices


I am trying to host a WF4 (RC) Service dynamically. I have a test solution with two projects. The first is a declarative workflow service library with one root Flowchart activity in it, and a simple custom code activity. The workflow service library does not depend on any other custom assemblies or references. The second is my host app, which in my test solution is just a console application.

In my host app, I am attempting to the use ActivityXamlServices to load the Xaml for the workflow service into an activity, and then use the WorkflowServiceHost to fire up a workflow instance using that activity.

As soon as I try to new up the WorkflowServiceHost object, I get this exception...

Cannot create unknown type '{clr-namespace:DeclarativeServiceLibrary1}CodeActivity1'.

If I remove CodeActivity1 from my Flowchart designer, everything runs fine. If I add a direct reference to the workflow service project from my host project and then create a WorkflowServiceHost using an instance of my Flowchart activity instead of the activity created from the Xaml, it also works fine.

It seems to not like using my CodeActivity for some reason when loaded dynamically.

Themes/Generic.xaml issue when file is Link from another project


I have two Project A and B that use a Themes project. In the Themes project, I defined a Generic.xaml file. If I run the program on the A project, it works.

But in the second project (B) I don't create the Generic.xaml file but link (add existing item -> add as link) it from the first project (A). When I run this one I got this error :

'/Theme;component/Themes/Generic.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'themes/generic.xaml'.  Error at object 'System.Windows.ResourceDictionary' in markup file 'AssemblyProjectB;component/app.xaml' Line 9 Position 37.

If in the second project (B) I create the file instead of linking the generic.xaml created in the first project (A), it works.

Any idea ?


svcutil /metadata - how to export metadata for service contract that has generic type



I am using svcutil /metadata to get metadata for a WCF service project assembly, the service class implements the IChildServiceContract below, and the IChildServiceContract interface implements a base interface which accept a generic type.

public interface IChildServiceContract : IServiceBaseContract<string>

I can generate metadata for IChildServiceContract , I am curious and also want to try generate meta data for base interface, an error come up which seems have problem with the generic based contract:

There was an error exporting the contract loaded from the type: xxx.xxx.xxx.IServiceBaseContract`1

Is it possible to generate metadata in this situation?


Thanks in advanced


How to set a style's TargetType property in XAML to a Generic Class?


I've just moved to .NET 4.0 / Visual Studio 2010 and am hoping there is a new answer to this question, found on StackOverflow from over a year ago:

Is it possible to set a style's TargetType property in XAML to a Generic Class?

public class Selector<T> : Control { }

and then in xaml

<Style x:TargetType="Selector">
<Setter Property="MyProperty" Value="Green" />

I found this on the WPF Tutorial, and would like to find a similar mechanism for this situation above.

<!-- XAML 2009 -->
<ObservableCollection x:TypeArguments="Employee">
 <l:Employee FirstName="John" Name="Doe" />
 <l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />



Generic type in AncestorType




I have a UserControl with some Labels and a ListBox as its children. I want do fill that ListBox via Binding to a derived generic dependency property of the UserControl:









Generic list with WebService throws 'Two Mappings for []' exception


Please consider below libraries:

ClassLibrary.dll (Smart Device Class Library project)

 public class B
        public string test;

 public class C
        public List<B> tempList = new List<B>();

WebServie (.NET 2.0)

Contains reference of ClassLibrary.dll
public class Service1 : System.Web.Services.WebService

        public List<B> ListOfB( string str)
            B obj = new B();           
            obj.test = str;

            List<B> list = new List<B>();

Using the generic type 'System.Collections.Generic.IEnumerable' requires '1' type arguments



I'm trying to create a control out of a class I found, and one of the overridden functions is the following:

protected override void PerformDataBinding(IEnumerable data)

However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.

Anyone able to help out?

Is there a plan to support a custom activity type as a root document in xaml on VS workflow designer



Referring to the post below. It seems that the current VS workflow designer only support "Activity" type as a root document. Is there a plan to support a custom activity type as a root document in xaml on next release of WF?




Issue with x:TypeArguments, generic List class, and XAML


I created the following markup for a loose XAML file.

<scg:List x:TypeArguments="sys:String">

But I get this error when I run the loose XAML in IE:

The tag 'List' does not exist in XML namespace 'clr-namespace:System.Collections.Generic;assembly=mscorlib'. Line '7' Position 2'.

As you would know, generics in XAML are a feature in XAML 2009 and can work for the most part only in loose XAML files. But the above code doesn't work.<

SQL Tracking Service XAML only (Type, Workflow and Activity db tables)


Ok, we've implemented workflow completely into our system now and I've starting to see the tracking database grow fairly quickly, which was expected


I am now working on a purge routine and or partitioning.


What I have noticed is that the Workflow and Type db tables will constantly grow no matter what.  They are not considered "partitioned" tables.


My main question is the architectural decision around this XAML only approach of tracking versus the code behind\beside approach.  I have a hypothesis I will present below.


In code behind\beside.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend