.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

Generic.xaml and Resources stored in App.xaml

Posted By:      Posted Date: September 05, 2010    Points: 0   Category :WPF
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  

View Complete Post

More Related Resource Links

Referencing image file stored in project resources through XAML



I'm sure this is super simple but I can't seem to figure this out.  Here is my scenario:

I have a bunch of .jpg image files that are included in a resources folder inside my project.  I want to reference them in XAML as follows:

<Image Name="SobeysImage" Stretch="Fill" ToolTip="Sobeys Image" FlowDirection="LeftToRight" Grid.Column="1" Source="Resources/sobeys1.jpg">

I get the following error message when I try to run the application:

Error 2 The file Resources\Sobeys1.jpg is not part of the project or its 'Build Action' property is not set to 'Resource'. C:\_Development\PhotoTool\PhotoTool\Window1.xaml 10 117 PhotoTool


I made sure that I set the build action of the image to Resource.


What am I missing???

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>?

Accessing Generic Type 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>?

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 ?


XAML resources


can i define an already instantiated local class varible as resource only using XAML?


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 />



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.<

What's new in XAML of .NET 4.0

With .NET 4.0 Microsoft will bring up a improved version of XAML. This arcitle shows you the language enhancements they made.
Easy Object References with {x:Reference}

Built-in Types

Generics in XAML with x:TypeArguments

Support for Arbitrary Dictionary Keys

Use of Non-Default Constructors with x:Arguments

Use of Static Factory Methods with x:FactoryMethod

Silverlight: Create Animations with XAML and Expression Blend


In this excerpt from his upcoming book, Laurence Moroney explains the basics of Silverlight animation and the animation tools available in Expression Blend.

Lawrence Moroney

MSDN Magazine August 2008

Help with creating dynamic XAML

Hi,  I need some help creating a complex XAML. I have a HotelRoom table with the below fields, ID Hotel HotelName Date RoomType Quantity  1    34    Hilton        3/5     Single      30  2    34    Hilton        3/6     Single      30  3    34    Hilton        3/7    Double     100  4    39    Express     3/5     King         10  5    39    Express     3/6    Double      20 Now I want the UI to display as a list of different records of Hotels with room details in them and I have created an object that has all the fields from the HotelRoom table,   HILTON               Single     Double    3/5        30          0    3/6 &n

How to load a usercontrol xaml at runtime ???????

Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

Disable XAML Intellisense in Macro (VS2010 IDE)

I'm writing a few macros to insert XAML code I often use into the VS2010 XAML editor. This works OK, but Intellisense is interpreting the code as it's being inserted. This causes syntax errors. Here's an example of the inserted code: <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> </Grid> The inserted code is a bit more complex as it includes properties I commonly use, but this will help illustrate the problem.When the code is inserted, Intellisense completes the definitions. For example, after <Grid> is inserted, Intellisense adds a corresponding </Grid>, which makes the code syntatically incorrect.How can I automatically disable Intellisense before the code is inserted and enable it after (within the macro)? After the code is inserted, I'd like to automatically reformat it.Thanks!

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.  

VS2010 XAML namespace intellisense not working

When I type in a namespace in XAML, I'm not getting any intellisense. For example: xmlns:local="" In VS2008 I would get a long intellisense list here. In VS2010 I get nothing. I have tried this on 2 different computers. What am I missing?

XAML - ValueConverter Parameters and PropertyChanged callback

Hi I am trying to use a IValueConverter on the flowdocument of a richtextbox. However, ideally I'd like to be able to inject some dependencies into the converter on construction or perhaps with a setter of some sort. Previously I've been using an IoC to construct a formatter-type object and can obviously specify the constructor dependency quite easily. However, I was hoping to use XAML and the IValueConverter as much as possible, but specifying the converter in the Grid.Resources requires a parameterless constructor. Are there other ways in which I can do this or do I need to think about the problem differently. In addition, because you cannot bind to a RichTextBox, I have introduced an AttachedProperty. Here's some code     Public Shared ReadOnly DocumentProperty As DependencyProperty = DependencyProperty.RegisterAttached("Document", GetType(FlowDocument), GetType(RichTextBoxExtensions), RichTextBoxFrameworkPropertyMetaData) Private Shared Function RichTextBoxFrameworkPropertyMetaData() As FrameworkPropertyMetadata Dim metaData = New FrameworkPropertyMetadata metaData.BindsTwoWayByDefault = True metaData.AffectsRender = True metaData.PropertyChangedCallback = New PropertyChangedCallback(Sub(obj, e) If _recursionProtection.Contains(Thread.CurrentThread) Then Return Dim rtb = CType

Accessing IO resources from CLR stored procedure

Hi There I am trying to write a CLR stored procedure that will return all the data about the fixed drives on a SQL server. Here is my code: using   System; using   System.Data; using   System.Data.SqlClient; using   System.Data.SqlTypes; using   Microsoft.SqlServer.Server; using   System.IO;   public   partial class StoredProcedures { [Microsoft.SqlServer.Server. SqlProcedure]   public static void Test() {   SqlPipe sp = SqlContext.Pipe;   String strCurrentTime = DiskSpace(); sp.Send(strCurrentTime); }   //[Microsoft.SqlServer.Server.SqlFunction(SystemDataAccess =SystemDataAccessKind.Read)]   //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted =true)]   public static string DiskSpace() {   new System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();   String Drives = "";   DriveInfo[] allDrives = DriveInfo.GetDrives();   foreach (DriveInfo d in allDrives) { Drives = ( "Drive " + d.Name);   //Console.WriteLine(" File type: {0}", d.DriveType);   if (d.IsReady == true) { Drives += " Volume label: " + d.VolumeLabel;   //Console.WriteLine(&qu

Error trying to open WPF Xaml windows from Visual Studio 2010 in Blend 4

Hi I have Visual Studio 2010 ultimate, and expression Blend 4. I have created a WPF 4 project in Visual Studio and when i try to open the MainWindow.xaml file in Expression Blend 4 - i get an error stating that the file or folder is not a valid blend project. Is there something i need to install for visual studio to make blend able to edit WPF Xaml files in Blend 4? I can open blend4 and create WPF applications with no problem - its just trying to open a mainwindow.xaml created in Visual Studio 2010 in blend 4 when i get the error. I am running windows 7 32 bit. Cheers Rod. Mono / DotNet Rocks!
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