Pseudo example:
<Window> <Window.Tag> <x:Dictionary KeyType="{x:Type sys:String}" ValueType="{x:Type sys:Int32}"> <sys:DictionaryEntry Entry="{sys:DictionaryEntry Key0, 000}"/> <sys:DictionaryEntry Key="key1" Value="111"/> <sys:DictionaryEntry> <sys:DictionaryEntry.Key> <sys:String>Key2<sys:String> </sys:DictionaryEntry.Key> <sys:DictionaryEntry.Value> <sys:Int32>222</sys:Int32> </sys:DictionaryEntry.Value> </sys:DictionaryEntry> </x:Dictionary /> </Window.Tag> </Window>
A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.
Tip You can create a resource dictionary file in Microsoft Visual Studio by using the Add > New Item… > Resource Dictionary option from the Project menu. Here, you define a resource dictionary in a separate XAML file called Dictionary1.
In Extensible Application Markup Language (XAML), the ResourceDictionary class is typically an implicit collection element that is the object element value of several Resources properties, when given in property element syntax. For details on implicit collections in XAML, see XAML Syntax Terminology.
A ResourceDictionary is a repository for resources that are used by a Xamarin. Forms application. Typical resources that are stored in a ResourceDictionary include styles, control templates, data templates, colors, and converters.
You can't use the Dictionary<TKey, TValue>
class directly in XAML, because there's no way to specify the generic type arguments (it will be possible in the next version of XAML, but it won't be supported in VS2010 WPF designer... at least not in the initial release).
However, you can declare a non-generic class that inherits from Dictionary<TKey, TValue>
, and use it in XAML.
C#
public class MyDictionary : Dictionary<string, int> { }
XAML
<Window> <Window.Tag> <local:MyDictionary> <sys:Int32 x:Key="key0">0</sys:Int32> <sys:Int32 x:Key="key1">111</sys:Int32> <sys:Int32 x:Key="key2">222</sys:Int32> </local:MyDictionary /> </Window.Tag> </Window>
If the keys and values are strings, you can use ListDictionary or HybridDictionary.
For example:
<Specialized:ListDictionary x:Key="MasterSlidesFileNames"> <System:String x:Key="long">Ya long yes ni</System:String> <System:String x:Key="Sun">Waterfall</System:String> <System:String x:Key="lorem ipsum">hello wOrld</System:String> </Specialized:ListDictionary>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With