[NUI] Add ControlStateTypeConverter for xaml (#2185)
authorYeongJong Lee <cleanlyj@naver.com>
Fri, 27 Nov 2020 05:09:53 +0000 (14:09 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 1 Dec 2020 08:56:39 +0000 (17:56 +0900)
commit33ae18063254ba9540e2ae76298361c98d95b156
tree6a559a84bb7e8c11e92f38d50cf63b8e942f5be2
parent1adb616ae37fb6136ce797da5c0737f1cb6219f2
[NUI] Add ControlStateTypeConverter for xaml (#2185)

Custom ConstrolState is now available in xaml.

 ### Sample
XamlPage.xaml
```xaml
<View x:Class="NUIXamlTemplate1.XamlPage"
      xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
      xmlns:local="clr-namespace:NUIXamlTemplate1">
    <local:MyButton x:Name="MyButton">
        <x:Arguments>
            <c:ButtonStyle Size="100, 100">
                <c:ButtonStyle.BackgroundColor>
                    <Selector x:TypeArguments="Color" Normal="1, 1, 0, 1" Pressed="0.77, 0.88, 1, 1" Disabled="0.88, 0.88, 0.88, 1">
                        <SelectorItem x:TypeArguments="Color" State="MyState" Value="0,0,1,1" />
                        <SelectorItem x:TypeArguments="Color" State="MyState,Focused" Value="0,1,1,1" />
                    </Selector>
                </c:ButtonStyle.BackgroundColor>
            </c:ButtonStyle>
        </x:Arguments>
    </local:MyButton>
</View>
```

MyButton.cs
```cs
public class MyButton : Button
{
    public MyButton(ButtonStyle buttonStyle) : base(buttonStyle) {}
    public void SetControlState(ControlState s) => ControlState = s;
}
```
Main.cs
```cs
protected override void OnCreate()
{
    base.OnCreate();
    Window.Instance.BackgroundColor = new Color(227 / 255f, 255 / 255f, 227 / 255f, 1.0f);
    Window.Instance.KeyEvent += OnKeyEvent;

    View root = new View();
    root.WidthSpecification = LayoutParamPolicies.MatchParent;
    root.HeightSpecification = LayoutParamPolicies.MatchParent;
    root.Layout = new AbsoluteLayout();
    Window.Instance.GetDefaultLayer().Add(root);

    XamlPage xamlPage = new XamlPage();
    root.Add(xamlPage);

    ControlState MyState = ControlState.Create("MyState");

    Button button = new Button() { Position2D = new Position2D(100, 100) };
    bool flag = false;
    button.Clicked += (object sender, ClickedEventArgs e) =>
    {
        if (!flag)
        {
            xamlPage.MyButton.SetControlState(MyState);
            flag = true;
        }
        else
        {
            xamlPage.MyButton.SetControlState(ControlState.Focused + MyState);
            flag = false;
        }
    };
    root.Add(button);
}
```
src/Tizen.NUI/src/public/BaseComponents/ControlState.cs
src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs