create ui-control



<UserControl x:Class="Asml.Stars.Sensing.Tasks.UserInterface.Tool.Dashboard.Common.SingleStateControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             HorizontalAlignment="Stretch"
	         VerticalAlignment="Stretch"
	         HorizontalContentAlignment="Stretch"
	         VerticalContentAlignment="Stretch"
             d:Height="auto" Width="auto">
    <Button Content="{Binding CurrentValue}" Command="{Binding ClickCommand}" Width="{Binding ButtonWidth}" 
      Height="26" VerticalAlignment="Center" Cursor="Hand" Margin="2" Background="LightSkyBlue"/>
</UserControl>


// create one property

        public static readonly DependencyProperty CurrentValueProperty =
            DependencyProperty.RegisterAttached("CurrentValue", typeof(string),
                                                typeof(SingleStateControl), new FrameworkPropertyMetadata(string.Empty));
        [Bindable(true)]
        public string CurrentValue
        {
            get { return (string)GetValue(CurrentValueProperty); }
            set { SetValue(CurrentValueProperty, value); }
        }


// usage 
// Binding ChangePolarisation
            <DockPanel Grid.Row="2" LastChildFill="True">
                <Label Content="Polarisation" Width="75" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <uiControls:SingleStateControl CurrentValue="{Binding CurrentPolarisation}" ClickCommand="{Binding ChangePolarisation}"/>
            </DockPanel>

// D:\dev\views\git_3\yieldstar\STARSvb0\Sensing\Tasks\UserInterface\Tool\Dashboard\Common\SensingIlluminationStateViewModel.cs
// current value : currentPolarisation 
// click command : ChangePolarisation

// clickCommand, CurrentValue -> binding 

        public string CurrentPolarisation
        {
            get { return m_CurrentPolarisation; }
            set
            {
                m_CurrentPolarisation = value;
                NotifyOfPropertyChange(() => CurrentPolarisation);
            }
        }
        
        
        public ICommand ChangePolarisation
        {
            get
            {
                return m_ChangePolarisation ?? (m_ChangePolarisation = new ClickCommand(() =>
                {
                    if (AvailablePolarisations != null && SetPolarisationAction != null)
                    {
                        OpenStateChangeDialog(new SingleStateChangeDialogViewModel(AvailablePolarisations, CurrentPolarisation), SetPolarisationAction, "Polarisation");
                    }
                }));
            }
        }
        
        
        public SingleStateChangeDialogViewModel(IEnumerable<string> availableStates, string currentState)
        {
            AvailableStates = new ObservableCollection<string>(availableStates);
            m_SelectedState = currentState;
        }




        protected void OpenStateChangeDialog<T1, T2>(
        T1 stateChangeDialog, 
        Action<T2> changeAction, 
        string dialogTitle = "") where T1 : StateChangeDialogViewModelBase<T2>
        {
            stateChangeDialog.Title = dialogTitle;
            stateChangeDialog.PropertyChanged += (sender, e) =>
            {
                var stateChangeVm = sender as T1;
                if (stateChangeVm != null && stateChangeVm.IsStateChanged)
                {
                    changeAction(stateChangeVm.SelectedState);
                }
            };
            m_WindowService.ShowViewModelDialog(stateChangeDialog);
        }


contract example


// D:\dev\views\git_3\yieldstar\STARSvb0\Contracts\MachineControl\Sensing\IFocusStatePublisherContract.cs
// add one contractCallback to get info to ui 


// Source
./Contracts/MachineControl/Sensing/IFocusStatePublisherContract.cs:        void OnNewFocusAcquisitionState(FocusAcquisitionState focusAcquisitionState);
./MachineControlling/Services/FocusStatePublisherService.cs:                   callback.OnNewFocusAcquisitionState(new FocusAcquisitionState

// UI
./Sensing/Tasks/UserInterface/Tool/Dashboard/Common/FocusStateViewModel.cs:        public void OnNewFocusAcquisitionState(FocusAcquisitionState focusAcquisitionState)
./Sensing/Tasks/UserInterface/Tool/Dashboard/PTS/DashboardPTSViewModel.cs:        public void OnNewFocusAcquisitionState(FocusAcquisitionState state)

//
// D:\dev\views\git_3\yieldstar\STARSvb0\Sensing\Tasks\Tool\Dashboard\PTS\DashboardPTS.cs

        public void SetSwitchMirrorMode(DashboardSwitchMirrorMode dashboardSwitchMirrorMode)
        {
            var switchMirrorMode = dashboardSwitchMirrorMode == DashboardSwitchMirrorMode.DarkField ? SwitchMirrorModeState.DarkField : SwitchMirrorModeState.Pupil;
            m_ChangeRequests.Enqueue(new SwitchMirrorModeChangeRequest( switchMirrorMode ));
            m_AcquireImageEvent.Set();
        }