private void OnClickInternal(ClickEventArgs eventArgs)
{
+ Command?.Execute(CommandParameter);
OnClick(eventArgs);
Extension?.OnClick(this, eventArgs);
ClickEvent?.Invoke(this, eventArgs);
using System.ComponentModel;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
+using System.Windows.Input;
namespace Tizen.NUI.Components
{
[EditorBrowsable(EditorBrowsableState.Never)]
public class Control : VisualView
{
+ /// Internal used.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
+
+ /// Internal used.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(Button), null,
+ propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).CommandCanExecuteChanged(bindable, EventArgs.Empty));
+
/// <summary> Control style. </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
Initialize(style);
}
- internal void ApplyAttributes(View view, ViewStyle viewStyle)
+ /// Internal used.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ICommand Command
+ {
+ get { return (ICommand)GetValue(CommandProperty); }
+ set { SetValue(CommandProperty, value); }
+ }
+
+ /// Internal used.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object CommandParameter
{
- view.CopyFrom(viewStyle);
+ get { return GetValue(CommandParameterProperty); }
+ set { SetValue(CommandParameterProperty, value); }
}
/// <summary>
internal bool IsFocused { get; set; } = false;
+ internal void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
+ {
+ ICommand cmd = Command;
+ if (cmd != null)
+ cmd.CanExecute(CommandParameter);
+ }
+
+ internal void OnCommandChanged()
+ {
+ if (Command != null)
+ {
+ Command.CanExecuteChanged += CommandCanExecuteChanged;
+ CommandCanExecuteChanged(this, EventArgs.Empty);
+ }
+ }
+
/// <summary>
/// Dispose Control and all children on it.
/// </summary>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<b:View x:Class="Tizen.NUI.Examples.CommandDemo"
+ xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
+ xmlns:b="clr-namespace:Tizen.NUI.BaseComponents;assembly=Tizen.NUI"
+ xmlns:u="clr-namespace:Tizen.NUI.UIComponents;assembly=Tizen.NUI"
+ xmlns:l="clr-namespace:Tizen.NUI.Examples"
+ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
+
+ <View.BindingContext>
+ <l:NameViewModel x:Name="nameViewModel"/>
+ </View.BindingContext>
+
+ <b:TextLabel Text="UserName" Size2D="300,50" Position2D="500,200" BackgroundColor="Yellow" PointSize ="20"/>
+ <b:TextLabel Text="{Binding UserName}" Size2D="300,50" Position2D="500,270" BackgroundColor="Blue" PointSize ="20"/>
+ <b:TextLabel Text="CompanyName" Size2D="300,50" Position2D="500,340" BackgroundColor="Yellow" PointSize ="20"/>
+ <b:TextLabel Text="{Binding CompanyName}" Size2D="300,50" Position2D="500,410" BackgroundColor="Blue" PointSize ="20"/>
+ <c:Button Text="Update" Size2D="200,100" Position2D="500,480" Command="{Binding UpdateName}"/>
+</b:View>
--- /dev/null
+using System;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Tizen.NUI.Examples
+{
+ public class NameModel
+ {
+ string userName;
+ string companyName;
+
+ public string UserName
+ {
+ get
+ {
+ return userName;
+ }
+ set
+ {
+ userName = value;
+ }
+ }
+
+ public string CompanyName
+ {
+ get
+ {
+ return companyName;
+ }
+ set
+ {
+ companyName = value;
+ }
+ }
+ }
+
+ public class NameViewModel : INotifyPropertyChanged
+ {
+ public NameViewModel()
+ {
+ userName = new NameModel()
+ {
+ UserName = "Adun",
+ CompanyName = "Samsung"
+ };
+ }
+
+ NameModel userName;
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public string UserName
+ {
+ get
+ {
+ return userName.UserName;
+ }
+ set
+ {
+ userName.UserName = value;
+ RaisePropertyChanged("UserName");
+ }
+ }
+
+ public string CompanyName
+ {
+ get
+ {
+ return userName.CompanyName;
+ }
+ set
+ {
+ userName.CompanyName = value;
+ }
+ }
+
+ private void RaisePropertyChanged(string propertyName)
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+ if (null != handler)
+ {
+ handler(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ void UpdateNameExecute()
+ {
+ UserName = "Xiaohui Fang";
+ }
+
+ bool CanUpdateNameExecute()
+ {
+ return true;
+ }
+
+ public ICommand UpdateName { get { return new RelayCommand(UpdateNameExecute, CanUpdateNameExecute); } }
+ }
+
+ public class RelayCommand : ICommand
+ {
+ readonly Func<Boolean> _canExecute;
+ readonly Action _execute;
+
+ public RelayCommand(Action execute)
+ : this(execute, null)
+ {
+ }
+
+ public RelayCommand(Action execute, Func<Boolean> canExecute)
+ {
+ if (execute == null)
+ throw new ArgumentNullException("execute");
+
+ _execute = execute;
+ _canExecute = canExecute;
+ }
+
+ public event EventHandler CanExecuteChanged
+ {
+ add
+ {
+ if (_canExecute != null)
+ {
+ //CommandManager.RequerySuggested += value;
+ }
+ }
+ remove
+ {
+ if (_canExecute != null)
+ {
+ //CommandManager.RequerySuggested -= value;
+ }
+
+ }
+ }
+
+ [DebuggerStepThrough]
+ public bool CanExecute(Object parameter)
+ {
+ return _canExecute == null ? true : _canExecute();
+ }
+
+ public void Execute(Object parameter)
+ {
+ _execute();
+ }
+ }
+
+ public partial class CommandDemo
+ {
+ public CommandDemo()
+ {
+ InitializeComponent();
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tizen.NUI.Components;
+
+namespace Tizen.NUI.Examples
+{
+ public class CommandDemoApplication : NUIApplication
+ {
+ protected override void OnCreate()
+ {
+ CommandDemo demo = new CommandDemo();
+ Window.Instance.Add(demo);
+ }
+ }
+}
// new TestAmbient().Run(args);
// new TestDetailApps().Run(args);
// new TestMyContents().Run(args);
+ // new CommandDemoApplication().Run(args);
/* For UTC codes */
// new TestButton().Run(args);
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Tizen.NET" Version="8.0.0.15214" />
+ <PackageReference Include="Tizen.NET" Version="8.0.0.15258" />
<PackageReference Include="Tizen.NET.Sdk" Version="1.0.0" />
<PackageReference Include="Tizen.NUI.XamlBuild" Version="1.0.11" />
</ItemGroup>
<None Remove="res\layout\TextFieldTestPage.xaml" />
<None Remove="res\layout\TextLabelTestPage.xaml" />
<None Remove="res\layout\VideoViewPage.xaml" />
+ <None Remove="CommandDemo\CommandDemo.xaml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="res\layout\1920x1080\AmbientDuoPage.xaml" />
<EmbeddedResource Include="res\layout\TextFieldTestPage.xaml" />
<EmbeddedResource Include="res\layout\TextLabelTestPage.xaml" />
<EmbeddedResource Include="res\layout\VideoViewPage.xaml" />
+ <EmbeddedResource Include="CommandDemo\CommandDemo.xaml" />
</ItemGroup>
-
</Project>