使用 x:Static 向 xaml 内的数组添加值
Adding value to array within xaml using x:Static
例如,我必须在 xaml
中使用字符串数组
<x:Array Type="sys:String" x:Key="Statuses">
<sys:String>Ok</sys:String>
<sys:String>Warning</sys:String>
<sys:String>Error</sys:String>
</x:Array>
但是如果我必须通过 x:Static
评估项目怎么办?可能吗 ?以下代码无效。
<x:Array Type="system:String" x:Key="Statuses">
<sys:String>
<Binding="{x:Static model:Status.Ok}" />
</sys:String>
<sys:String>
<Binding="{x:Static model:Status.Warning}" />
</sys:String>
</x:Array>
public enum Status
{
Ok,
Warning,
Error
}
所以我的问题是如何使用 x:Static
在 xaml
中初始化数组
我知道这个方法
[ContentProperty("Values")]
[ContentWrapper(typeof(Collection<State>))]
public class StateCollection
{
private const string DefaultKeySeparator = ",";
private string _keySeparator;
public string KeySeparator
{
get { return _keySeparator ?? DefaultKeySeparator; }
set { _keySeparator = value; }
}
private Collection<State> _values = new Collection<AlternationConverterItem>();
public Collection<State> Values
{
get { return _values; }
set { _values = value; }
}
}
public sealed class State
{
public Status Status { get; set; }
public String Description { get; set; }
}
<myNamespace:StateCollection x:Key="MyCollection" KeySeparator="-">
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Ok}" Description="{StaticResource Description1}" />
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Warning}" Description="{StaticResource Description2}" />
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Error}" Description="{StaticResource Description3}" />
</myNamespace:AlternationConverter2>
但我不知道如何对上面写的字符串数组应用相同的方法。
我已经成功使用了x:Static Member=
:
<x:Array x:Key="SiteOkKey" Type="system:Object">
<x:Static Member="model:RestoreObjectStatus.Ok" />
<x:Static Member="core:RestoreObjectTypes.Site" />
</x:Array>
例如,我必须在 xaml
<x:Array Type="sys:String" x:Key="Statuses">
<sys:String>Ok</sys:String>
<sys:String>Warning</sys:String>
<sys:String>Error</sys:String>
</x:Array>
但是如果我必须通过 x:Static
评估项目怎么办?可能吗 ?以下代码无效。
<x:Array Type="system:String" x:Key="Statuses">
<sys:String>
<Binding="{x:Static model:Status.Ok}" />
</sys:String>
<sys:String>
<Binding="{x:Static model:Status.Warning}" />
</sys:String>
</x:Array>
public enum Status
{
Ok,
Warning,
Error
}
所以我的问题是如何使用 x:Static
xaml
中初始化数组
我知道这个方法
[ContentProperty("Values")]
[ContentWrapper(typeof(Collection<State>))]
public class StateCollection
{
private const string DefaultKeySeparator = ",";
private string _keySeparator;
public string KeySeparator
{
get { return _keySeparator ?? DefaultKeySeparator; }
set { _keySeparator = value; }
}
private Collection<State> _values = new Collection<AlternationConverterItem>();
public Collection<State> Values
{
get { return _values; }
set { _values = value; }
}
}
public sealed class State
{
public Status Status { get; set; }
public String Description { get; set; }
}
<myNamespace:StateCollection x:Key="MyCollection" KeySeparator="-">
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Ok}" Description="{StaticResource Description1}" />
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Warning}" Description="{StaticResource Description2}" />
<myNamespace:State Status="{x:Static model:RestoreObjectStatus.Error}" Description="{StaticResource Description3}" />
</myNamespace:AlternationConverter2>
但我不知道如何对上面写的字符串数组应用相同的方法。
我已经成功使用了x:Static Member=
:
<x:Array x:Key="SiteOkKey" Type="system:Object">
<x:Static Member="model:RestoreObjectStatus.Ok" />
<x:Static Member="core:RestoreObjectTypes.Site" />
</x:Array>