.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

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

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :WPF


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

View Complete Post

More Related Resource Links

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

Basic Instincts: Static Event Binding Using WithEvents


This month's Basic Instincts column builds upon my last three columns in which I introduced and explained the fundamental concepts and syntax associated with delegates and events. Last month I showed you how to design and write a simple class that defines and raises events.

Ted Pattison

MSDN Magazine March 2003

Cache vs Static Class

Hi All, I am sure this question has been posted many times, but have not got time to wade through. Apologies in advance! I am working on a new web application which has extremely high volumes of traffic, the application uses two large(ish) data tables (approx 15,000 rows/records each - both fairly 'wide' tables....) which are each the result of various JOINS and other intensive operations. The post query operations are unavoidable and the data structure has been optimised wherever possible. I am debating on using the Cache and CacheDependancy classes to store these tables, but fear the 'eviction' process due to the demand in traffic and server resources generally. I can certainly afford to build these tables once, on the first request (near Application Start), but should memory become scarce, do not want the cached data to be recreated during the application lifecycle and have concerns about how ASP.NET will manage demands on this data in such a crisis. For example, if during a period of time, available memory is at an all time low, I would anticipate that the CacheDependancy would keep recreating the tables for each request. (I don't know...) Note: The Cache API is not used elsewhere and the Application and Session scopes are hardly used. At present, I am using just a static class to store the two tables which works a

Working with System.IO.Path static class

Hello everyone. Today, I was exploring the System.IO namespace in .NET 4.0 on an ASP.NET web application where I came to few changes, comparing with the previous versions of .NET, related to the System.IO.Path static class. The Path class contains the same method names in .NET 2.0, 3.5 as well as 4.0, only (in .NET 4.0) new overloads are added to System.IO.Path.Combine() method. In the following blog post, I will show the usage of few methods belonging to the System.IO.Path static class, as well as, the changes in Combine() method added in .NET 4.0. Besides the first method that is available in the previous versions for combining two string paths, now in .NET 4.0 you can combine unlimited strings to the path. Note: For testing purpose, on your web application root, create folders with name Files, Files/SubFolder, Files/SubSubFolder and add three text files: text1.txt (in Files), text2.txt (in Files/SubFolder), text3.txt (in Files/SubFolder/SubSubFolder).   Here are few examples:             string path1 = System.IO.Path.Combine(Server.MapPath("Files"), "text1.txt"); //this will give the path to %WEBAPP_ROOT%/Files/text1.text -             string path2 = System.IO.Path.Combine(Server.MapPath("Files"), "SubFolder", "text2.txt"); //this will give

ASP.NET: Using a static class and methods for the WCF client

Traditionally in our web pages we have instantiated a service client in each page and then called the WCF methods from that instance, adding some caching code to check if the data exists and if not, make the WCF call and cache the data for the next time. As our site grows we find we're repeating this same pattern and are looking to move it all to a single class. Can we make that class static, with a single static instance of the WCF client, and static methods, safely? // pseudo-code // assume WcfDataService has a GetFoo(int i) method public static class WcfMethods { public static WcfDataService client = new WcfDataService("connectionType"); public static DataSet GetFoo(int i) { if (Cache["foo" + i] == null) { Cache.Insert("foo" + i, client.GetFoo(i)); } return Cache["foo" + i] as DataSet; } } Then in our pages we can just call WcfMethods.GetFoo(x) directly.  Figure we have 100 users visiting our various pages simultaneously.  Will this cause contention issues?  Like I mentioned, up till now we've not used static instances.  It's not caused any problems, but we're just looking to refactor.  I realize we could also use the above pseudo-code pattern using an instance class and methods instead static ones. I haven't dealt with threading or synchro

Custom markup extension or custom binding class?

Hey experts! I'm doing a project where I've encountered an issue I'd love some feedback on. I've created a custom Markup Extension called MyMarkupExtension, with two properties.  I can use it like below: <cc:DialogBorder Title="{local:MyMarkupExtension MyProperty='property value goes here', AnotherProperty='and another value here'}"> It works, and in 99% of the cases, it fits my needs perfectly.  In 1% of the cases, the values of MyProperty and AnotherProperty can not be set at design time, so I'd need some binding there. <cc:DialogBorder Title="{local:MyMarkupExtension MyProperty={Binding Path='SomePropertyOfTheViewModel'}, AnotherProperty='and another value here'}"> This presents my two questions (yes I did make only one post for 2 questions, bad karma...): 1. the binding inside my markup is not legal, after all, a binding can only be set on a DependencyProperty.  Is there any workaround which I could use for this problem at hand? In case there isnt... 2. I'm thinking about dropping the markup extension and creating a custom binding instead.  For this, I'd have to inherit from bindingbase, and so far I've read online that's one ____ of a nightmare.  Does anyone have some good code / examples on where to start? "The improbable we do, the impossible just takes

Sharing of Non-Static member variables of a class using .NET Remoting

This kind of weird. I am trying to host an object of a class X (a class library class). This is a SAO and I have set the WellKnownMode as Singleton in the server configuration. <wellknown mode="Singleton" When multiple clients fetch the instance of the class X they can share the static member variables. Any changes made to the static variables are visible to each other. The problem is with the non-static member variables of the class. Each instance is having a local copy of the non-static variables. Why should that happen in case of a Singleton mode? Am I missing something for which this is happening? Any help will be appreciated.  A for apple, B for boy, C for c++

Dictionary class in MVC

hello guys,I do have Dictionary<Guid, Menu> where Guid is ID and Menu is my model for view which contains different  propertiesthat is :public class Menu    {        [Required(ErrorMessage = "Name is Required")]        public string Name { get; set; }        [Required(ErrorMessage = "Description is Required")]        public string Description { get; set; }    }now i do have extension method in which thru services i m assigning value to it..extension method is like this :public static Dictionary<Guid, Menu> GetMenuCategoriesModel(this IRService irService, IMCService imcService, Guid rIdmy question is that i have view named "Index" and in that view i wanna display "name" and i am generating strongly typed view and i have to use Dictionary<Guid, Menu> as model , how do i access Menu's properties as i wanna display name on the page ???Please suggest me..Thanks in advance

Problem with Binding Dictionary to Combo Box Control

Hi All,I am trying to figure out how to bind <Key,Value> pair to Combo Box Control in WPF. By now i have found that the following code do not hold Keys in the comboBox:[vb Code]Dim MyDictionary as Dictionary(OF String,String)MyDictionary.Add("Key1","Value1")MyDictionary.Add("Key2","Value2") ..etc.'***** MyComboBox is ComboBox control ******MyComboBox.ItemSource =  MyDictionary.Values[xmal]<xmls:ComboBox x:Name="MyComboBox" />Doing the above process does not fulfill my purpose of capturing keys. Example if i want to get the "Key" for "selectedItem" then i cannot since i have not binded it.Can anyone suggest me a solution? If anyone can provide me with a xmal and code behind that would be great!!!THanks in Advance.

Static and Dynamic Resources with Brush and Resource Dictionary

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?

Some Useful Properties of Binding Class

When binding the UI control with the data source the Binding class has some useful properties.In this post we will look at them and use them in sample application. The properties which we are going to discuss in this post are the FallbackValue ,TargetNullValue, and StringFormat. Image 1 shows the output of the example code.

binding dictionary with strongly typed view

hey guys ,i m beginner in asp.net mvc , i have strongly typed view and i m passing my dictionary in view as :Dictionary<Guid,IYummyWebAppMVC.Models.Restaurant.Menu>>" %> Dictionary<Guid , MyApp.Models.Res.Menu>  how do i access this in html ?how do i iterate thru it and get value of both the items ?

how to jquery call a other call function other class is not static

how to jquery call a other call function other class is not static[WebMethod]    public static bool Verify(string username, string password)    {        //Do your logic with username, password  here        //I am just checking with admin/admin credentials            Console.WriteLine("Ritu");        string s="SELECT p.RETMSG FROM P_DOCSHARE(1001,1453,'1002,1012,1011','Add') P";                 CCUtility c;                c=new CCUtility();             c.JavascriptMessage(c.Insert_P(s));        return (username == "admin" && password == "admin");    }

Binding ISSUE??? How To Bind Dictionary of Dictionary


Hi All I have Problem in binding 

i have object of Dictionary of Dictionary

like this 

ObservableSortedDictionary<string,Dictionary<string,string>>  coll = new ObservableSortedDictionary<string,Dictionary<string,string>>();

Dictionary<string,string> InnerData = new Dictionationry<string,string>():

innderData.add ( "Item1","Data1");

innderData.add ( "Item2","Data2");


i want to bind the inner dictionary (Data) into a GRIDVIEW 

can any one help me to Bind This Object??

ASAP please

Binding a treeview to a LinqToSQL class...


Hi all,

I have a LinQtoSQL class which encapsulates a table with the following relationship:

Id (int)
Parent ID(int)
Name (string)

Here, the parent ID is the id of another row int he same table. So, the table could look like:

1, null, grandpa
2,1, mom

What I want to do is the create a treeview that binds to the table so that it looks like this:


Also, I should be able to add or delete nodes/rows...

Any ideas on how to do this? Is this even possible without writing the code to do all the population and the edit etc?





Calling a static method in a static class from a base class.


I have the following static class and method:

public static class GenericList


      public static List<DocumentElement> PopulateGenericList()



What is the syntax to call the PopulteGenericList() method from a base class?



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