Page 20 - DCAP408_WEB_PROGRAMMING
P. 20

Windows Programming




                    Notes
                                     Did u know?  Each method takes the  resource key  as an input parameter, and returns a
                                     loosely typed object.
                                   Typically, a resource key is a string, but there are infrequent non-string usages; see the Using
                                   Objects as Keys  section for  details. Usually you would  cast the returned object to the  type
                                   required by the property that you are setting when requesting the resource.

                                       !

                                     Caution  The lookup logic for code resource resolution is the similar as the dynamic resource
                                     reference XAML case.
                                   The hunt for resources starts from the calling element, then persists to successive parent elements
                                   in the logical tree. The lookup continues onwards into application resources, themes, and system
                                   resources if essential. A code demand for a resource will properly account for runtime modifies
                                   in resource dictionaries that might have been made succeeding to that resource dictionary being
                                   loaded from XAML, and also for real-time system resource m.


                                          Example: The following is a concise code example that locates a resource by key and
                                   utilizes the returned value to put a property, executed as a Click event handler.














                                   1.7.2 Creating Resources with Code


                                   If you want to generate a whole WPF application in code, you might also desire to create any
                                   resources in that application in code. To attain this, create a new Resource Dictionary instance,
                                   and then add  all the  resources to  the dictionary by  means  of successive  calls to Resource
                                   Dictionary.Add. Then, use the Resource Dictionary thus generated to set the Resources property
                                   on  an element that is present in  a page scope, or  the Application.Resources. You could also
                                   preserve the Resource Dictionary as a separate object without adding it to an element. On the
                                   other hand, if you do this, you must access the resources within it by item key, as if it were a
                                   generic dictionary. A Resource Dictionary that is not associated to an element Resources property
                                   would not occur as part of the element tree and has no scope in a lookup sequence that can be
                                   used by Find Resource and associated methods.

                                   1.7.3 Different Data  Types used in  Resource File

                                   Microsoft Windows applications often depend on files that contain non-executable data, such as
                                   Extensible  Application  Markup  Language (XAML),  images,  video,  and  audio.  Windows
                                   Presentation Foundation (WPF) offers special support for configuring, identifying, and using
                                   these types of data files, which are called application data files. This support revolves around a
                                   specific set of application data file types, including:





          14                                LOVELY PROFESSIONAL UNIVERSITY
   15   16   17   18   19   20   21   22   23   24   25