如何使用< x:array> xaml语言中字符串的标记扩展 [英] how to use an <x:array> markup extension for strings in xaml language
本文介绍了如何使用< x:array> xaml语言中字符串的标记扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用< x:array xmlns:x =#unknown>对于xaml 4.0中的字符串,用于在wpf应用程序中实现动态资源,其中两个组合框具有3个字符串类型的元素
解决方案
你的意思是静态资源吗?这将在XAML中声明(虽然这在可维护性和可扩展性方面很糟糕......)
无论如何,如果你正在寻找静态资源,那么,
// 1.在您的Window标记声明使用.NET System命名空间
< window x: class = WpfTutorialSamples.WPF_Application.ExtendedResourceSample xmlns:x = #unknown >
xmlns = http://schemas.microsoft.com/winfx/2010/xaml/presentation
xmlns:x = http://schemas.microsoft.com/winfx/2010/xaml
xmlns:s = clr-namespace:System; assembly = mscorlib
Title = StaticResourceComboboxSample
高度= 400
Width = 300 >
// 2.现在,名称空间别名's'对应于System名称空间在mscorlib.dll中,它具有定义的标准类型。
// 3.创建静态资源,它具有一个密钥属性,稍后将使用该属性将该资源用于/关联到控件,例如在你的情况下组合框。
< x:array x:key = CBXDropdownItems type = s:String >
< s: string xmlns:s = #unknown> < / s :string >
< s: string xmlns:s = < span class =code-string> #unknown> B < / s:string >
< s: string xmlns:s = #unknown> C < / s:string >
< / / span> x:array >
// 4.现在,我们所要做的就是将此资源(密钥)与控件的数据源(ItemsSource属性)相关联。
< combobox itemssource = {StaticResource CBXDropdownItems} /> < / window >
how can i use <x:array xmlns:x="#unknown"> for strings in xaml 4.0 for implementing dynamic resources in wpf application in which two combobox having 3 elements of string type
解决方案
Do you mean a static resource? This would be declared in XAML (though this is bad from maintainability and extensibility aspects...)
Anyways, if you are looking for static resource then,
// 1. In your Window tag declare usage of .NET System namespace <window x:class="WpfTutorialSamples.WPF_Application.ExtendedResourceSample" xmlns:x="#unknown"> xmlns="http://schemas.microsoft.com/winfx/2010/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2010/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" Title="StaticResourceComboboxSample" Height="400" Width="300"> // 2. Now, namespace alias 's' corresponds to System namespace in mscorlib.dll and this has the standard types defined. // 3. Create a static resource, it has a key property which will be used later to use/associate this resource to a control e.g. combo-box in your case. <x:array x:key="CBXDropdownItems" type="s:String"> <s:string xmlns:s="#unknown">A</s:string> <s:string xmlns:s="#unknown">B</s:string> <s:string xmlns:s="#unknown">C</s:string> </x:array> // 4. Now all we have to do is associate this resource (key) to the control's data source (ItemsSource property). <combobox itemssource="{StaticResource CBXDropdownItems}" /></window>
这篇关于如何使用< x:array> xaml语言中字符串的标记扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文