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

Top 5 Contributors of the Month
Post New Web Links

Static and Dynamic Resources with Brush and Resource Dictionary

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :WPF
Hi, We're using a huge resource dicionary with all the styles and templates for our controls. Some of these are the images that we use for some buttons and icons in the application. As far as I know, Static and Dynamic resources have nothing to do with the ResourceDictionary and The Brush, i could use any of them, if i need the resource to load only when needed i could use dynamic and if i want it to load on initialization time i should use Static. But everytime i try to use a static resource to define a Fill of a rectangle my application crashes on initialization time (when it exectues the InitializeComponents). The resource i'm using is a DrawingBrush that is declared on my resource dictionary and the only way i could make it works is defining it as DynamicResource. What is the limitation? Its realy impossible to define a static resource on a fill property, and if its realy impossible, why?

View Complete Post

More Related Resource Links

How to use Resource files added to Resources Folder ?



I have added .CSS file in Resources folder of the project.In the same way i can add Images or any other files.But i am unable to use those files in Server Control Project.How to apply CssClass property to any predefined server control to the css file that is stored in the Resources folder  ?

Please guide how to use those Resource files . 

Why can't I load an an external resource dictionary that contains type converters?

Basically what I'm doing is putting a bunch of type converters as resources in a ResourceDictionary contained in an externally referenced assembly. Let's call the assembly WpfCommon. I'm directly referencing the assembly from my main application. In the App.xaml:       <Application.Resources>         <ResourceDictionary>             <ResourceDictionary.MergedDictionaries>                 <ResourceDictionary Source="pack://application:,,,/Common.Wpf;component/Wpf/ResourceDictionaries/Converters/Converters.xaml"/>             </ResourceDictionary.MergedDictionaries>         </ResourceDictionary>     </Application.Resources>   Converters.xaml:   <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:Common_Wpf_Converters="clr-namespace:Common.Wpf.Converters">     <ResourceDictionary>         <Common_Wpf_Convert

Menu with Static and Dynamic Menu Items

I need to populate a menu with static and dynamic (at runtime) menu items.  I know this issue has been posted before, but I haven't seen anything with a date newer than 2009. This is what I want to do: <Menu> <Menu.ItemsSource>                     <CompositeCollection>                      <MenuItem Header="Menu Item 1" /> <MenuItem Header="Menu Item 2" /> <MenuItem Header="Menu Item 3" />                         <CollectionContainer Collection="{Binding MyMenuItems}" />                     </CompositeCollection> </Menu.ItemsSource> </Menu>   The posts every where say the issue is that CompositeCollection is not freezable.  Regardless of that arguement, has anyone come up with a good solution.  I don't want to create it all in code behind because it is a decent size menu with separators, etc.  This seems like something that should have been fixed or have a decent work round by now.   Thanks. 

Initializing CommandBindings in XAML using a CommandBindingCollection static resource

Hi, I have defined a CommandBindingCollection object in <Window.Resources> and now I would like to use it as multiple controls' <Control.CommandBindings>.  Unfortunately, I can't find the right syntax. Any help will be appreciated. Thanks.  

What is the recommended format for vector icons in resource dictionary?

It seems that Expression Design wants to export vector graphics in resource dictionary format as DrawingBrushes.  These are a bit of a pain to use in something like a MenuItem.Icon.  So I have been converting the DrawingBrushes to DrawingImages.  The only downside I've run into so far is that I can't figure out how to force the DrawingImage to be a certain size say 20x20 where the content may not take up that whole size.  The issue is that when you put these vector icons on a toolbar and you want the images to align, it is tricky when each icon is a slightly different height.

Setup Error - Failed to load resources from resource file

I tried to install The Lord of the Rings Online, but it always gives me the message (translated in english) that i need to install Net Framwork v1.1.4322. "ok, that's no problem" i thought, but every time i try to install Net Framework (any version) there are errors when trying to install it. With the 1.1 setup, it tells me "Setup Error - Failed to load resources from resource file", the 2.0 setup tells me that it is already installed (o.O?) but i can't see it in the "uninstall programs" list and the 3.0 and 3.5 just won't start. Nothing happens. I tried to install Net framework 4.0 beta which works fine but LotRO keeps telling me the same error message (i think because version 1.1 isn't included in higher versions)I'm running Windows 7 32 bit Ultimate: 2GB Ram, Intel Core duo e6750, GeForce 8800 gts (512 mb)Please help me :)

Unique Pack URIs for resources (embedded / content / resource files) in several assemblies

Hello, When using resources as files (build actione=none and copy if newer), I'm able to manage resources using something like this : "/file.ico". Whatever the owner assembly is, because all files are copied in the Debug / Release directory. I'd like to have a similar behavior with pack URIs. I don't want to specify which assembly is the owner of an embedded / content / resource file. It seems impossible because we need to specify the source assembly ("pack://assembly_08:,,,/file.ico"), I'd like something like : "pack://whatever_the_assembly:,,,/file.ico". Is it possible ? Any idea ? Thanks.

Unable to find static resource in runtime even while designer can see it

So i have:    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Werp.MigrationHelper"> <Style TargetType="{x:Type UserControl}" x:Key="WizardPageControl" x:Name="WizardPageControl"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type UserControl}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="10" /> <ColumnDefinition Width="475" /> <ColumnDefinition Width="10" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="10" /> <RowDefinition Height="410"/> <RowDefinition Height="50" /> <RowDefinition Height="10" /> </Grid.RowDefinitions> <StackPanel Orientation="Vertical" Name="MainContent" Grid.Row="1" Grid.Column="1"> <ContentPresenter Content="{TemplateBinding Content}"/> </StackPanel> <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center&qu

Requesting static resources

Hi!I created method IsMobileRequest(HttpContext ctx) that checks whether or not user agen is mobile browser. If it is mobile browser, application will redirect user to /mobile controller.Code in Global.asax for redirection handling:protected void Application_BeginRequest() { if(Helpers.MobileUtilities.IsMobileRequest(Context)) { HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current); RouteData routeData = RouteTable.Routes.GetRouteData(currentContext); String currentControllerName = currentControllerName = (String) routeData.Values["Controller"]; if (currentControllerName.ToLower() != "mobile") { Context.Response.Redirect("/mobile"); } } } This code succefully redirected all request to /mobile but when front-end developer inserted markup that loads static contents (/Content/Images, /Content/Styles, etc.) mobile page didn't render those static files.After some experimenting, I noticed that in ASP.NET MVC request for static files passes throught application stack (Global.aspx) as well as dynamic requests.This version of code addresses that issue:protected void Application_BeginRequest() { if(Helper

Percent of Total Calculation with Mixed Static and Dynamic Groups


Ok, here's one I'm really struggling with.  I have a report that has two dynamic row groups and three dynamic column groups that are nested beneath static column groups.  It looks similar to this:

                                                  Market Share                  Discharges                           LOS

                                                Column Group1               Column Group2               Column Group3

Row Group1  Row Group2       &

Wpf - User control or dictionary resource



i am beginner in programming WPF - and sorry for my English :).

I am trying lern to use namespace and class in WPF.

I have to question :

1) In the DictionaryResource I can create ContextMenu and later assign this ConterxtMenu to TextBox ( using StaticResource ).

The same I can achieve when I using UserControl ( I create ContextMenu as UserControl and assign to TextBox ).

Do any of these ways is preferred for certain applications such as DictionaryResource apply rather to give the appearance rather than creating the whole ContextMenu?

Are there other ways to share the code?

2) I created such a ContextMenu in ResourceDIctionary (in a separate file.) It has two entries such as "Show", "Close." Signed it to a TextBox in my main window.

And now how to call the (assigned) ContextMenu event to "Show" to change the text in the TextBox?

SQL 2008 R2 Dynamic Ports and Static Ports


We have a single application (Interaction) that needs the port number specified in the application itself in order to 'talk' to its SQL database. The SQL environment consists of a two node cluster with two named instances. Each of the instances are divided equally between the nodes. We are obviously using dynamic ports on both of our names instances. I gave the application owner the port that the instance the database is currently running on. He hasn't gotten back to me yet, however, I suspect that when he specifies that port in the application it will connect to the database just fine. If it does, I need to come up with a plan for this one application.

Is there a way to use both dynamic ports with a static port specified? In the TCP/IP properties under the instance name, dynamic ports are used because the 'TCP Dynamic Ports' is set to '0'. Can I set it to something like '0,5100'? That way it'll still use dynamic ports with a specific port to always listen on? It seems like a stretch, but I'd rather not change my whole environment due to one silly application.

Another solution is to maybe create another instance for this one application and set the port statically? That's also very silly in my opinion to have a dedicated instance with only one database to set a static port. If anyone has any other creative ideas, besides just using the

Does WPF implicit caching of static resources?



in my Application.Current.Resources.MergedDictionaries is a ResourceDictionary with theme specific resources. If the user selects another theme, the theme-depended control is removed from it's parent (Grid) and a splash screen is inserted instead. After replacing the theme-specific ResourceDictonary in the Application.Current.Resources.MergedDictionaries, the theme-depended control is created anew and replaces the splash screen. But, the control still uses the static resources from the replaced ResourceDirectory. Why? Is there any implicit resource caching in WPF? In the Silverlight port of the app, the static theme resources are applied correctly.  


WPF OneWay ItemsSource Binding to a static class's dictionary?



I have a global Static class which implements a dictionary of languages:

namespace Tools.DataAccess
  static public class Planner
    static public class Dictionaries
      static public Dictionary<UInt32, string> Languages { get; }

I am trying to bind a ComboBox's ItemSource to the static dictionary called "Languages". It works very well through code-behind at the moment:

ui_languages_cmo.ItemsSource = Tools.DataAccess.Planner.Dictionaries.Languages;

However I cannot bind it through XAML. The dictionary actually resides in a separate namespace (Tools) than my UserControl (myApp). Here's roughly what I'm trying to do:

<UserControl x:Class

Can't find resource dictionary


I'm using VS2010, .net 4, in a pure WPF app. I'm using the code here to customize an expander control


I've put the code in a separate xaml file (/Styles/ScreenStyles.xaml) and included it via my app.xaml file using a merged dictionary

<Application x:Class="WpfApplication1.App"

Include Button Click Event in WPF Resource dictionary's CodeBehind file

I have 3 buttons as a part of menu in my MainWindow.xaml file.  
On click of these I have a Common Grid that gets populated with the
 data from my database. Now for these i have set various Control
 templates with 3 different keys for my 3 different options.

Coming to my main point. When I include Click events under my
 Gridview and compile, it doesn't let me to do so cause of error.
 And to overcome this i made use of a Code behind C# Class file for
 my resourcedictionary (styles.xaml) that is styles.xaml.cs.
I got this from http://stackoverflow.com/questions/92100/is-it-possible-to- set-code-behind-a-resource-dictionary-in-wpf-for-event-handling

But As soon as i follow all procedure mentioned at above link it
says me ... Error Message: 'X' does not contain a definition for 'show'
 and no extension method 'show' accepting a first argument of
type 'X' could be found (are you missing a using directive or an

resource string $Resources:ReportServerResources,DataSourceContentTypeName


I am getting this wierd error in sharepoint 2010 with a custom template, hep me out thank you

resource string $Resources:ReportServerResources,DataSourceContentTypeName

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