1

For example, I have to use array of string inside my 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>

But what if I have to assing items via x:Static. Is it possible ? Following code doesn't work.

<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
}

So my question is how to initialize array within xaml using x:Static

I know this approach

[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>

But I don't kwni hot to apply the same way for array of string I've writen above.

2
  • it seems Items property does not have accessible setter so unfortunately you cant use object data provider like used in this way... stackoverflow.com/questions/6145888/… Commented Jun 2, 2016 at 12:12
  • @M.kazemAkhgary And ContentProperty and ContentWrapper couldn't help with this ? Commented Jun 2, 2016 at 12:24

1 Answer 1

4

I've successefully used 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.