Databound Placeholder text
(Created page with "Placeholder text is text shown as a hint to the user while the control is empty. As soon as the user enters a value the placeholder text is not shown. The old way was a tagge...")
 
No edit summary
Line 10: Line 10:


If you use the MaterialDesign package this code will ge the effect:
If you use the MaterialDesign package this code will ge the effect:
<pre>
      _wecpof = new WECPOFTabBased();
      _wecpof.OnWorkTrailInfo += new EventHandler<WorkTrailArgs>(_wecpof_OnWorkTrailInfo);
      _wecpof.OnGetUserZoomForWinType += _wecpof_OnGetUserZoomForWinType;
      _wecpof.OnSaveUserZoomForWinType += _wecpof_OnSaveUserZoomForWinType;
      _wecpof.OnAddWindow += (s, e) =>
      {
        e.Win.ViewModelUC.OnViewModelColumnPlacementDone += (s2, e2) =>
        {
          if (e2.Ctrl is System.Windows.Controls.TextBox || e2.Ctrl is System.Windows.Controls.ComboBox || e2.Ctrl is System.Windows.Controls.DatePicker)
          {
            var val = e2.Vcol.TaggedValueLocalAndModelInfo("Placeholder");
            if (!string.IsNullOrEmpty(val))
              MaterialDesignThemes.Wpf.HintAssist.SetHint(e2.Ctrl, val);
            var dataForPlaceholder = e2.Vcol.ViewModelClass.ColumnFromName(e2.Vcol.RuntimeName + "_Placeholder");
            if (dataForPlaceholder != null)
            {
              if (e2.Ctrl is FrameworkElement)
              {
                var b = new System.Windows.Data.Binding(dataForPlaceholder.RuntimeName) { Source = e2.Vcol.ViewModelClass.BindingSource, Mode = System.Windows.Data.BindingMode.OneWay /*, Converter = new Eco.Xaml.PassthroughDebugConverter() */ };
                (e2.Ctrl as FrameworkElement).SetBinding(MaterialDesignThemes.Wpf.HintAssist.HintProperty, b);
              }
            }
          }
        };
</pre>

Revision as of 08:33, 14 October 2022

Placeholder text is text shown as a hint to the user while the control is empty. As soon as the user enters a value the placeholder text is not shown.

The old way was a taggedvalue "Placeholder" along with the desired text to show "Enter a search string..." - this will be deprecated

The new way is to name an additional column with postfix _Placeholder in its name - the result of the expression will be used as a placeholder text.

In Turnkey this has been available since early 2022

In WPF you will need to add code - since the out-of-the-box controls of WPF does not support placeholder texts.

If you use the MaterialDesign package this code will ge the effect:

      _wecpof = new WECPOFTabBased();

      _wecpof.OnWorkTrailInfo += new EventHandler<WorkTrailArgs>(_wecpof_OnWorkTrailInfo);
      _wecpof.OnGetUserZoomForWinType += _wecpof_OnGetUserZoomForWinType;
      _wecpof.OnSaveUserZoomForWinType += _wecpof_OnSaveUserZoomForWinType;
      _wecpof.OnAddWindow += (s, e) =>
      {
        e.Win.ViewModelUC.OnViewModelColumnPlacementDone += (s2, e2) =>
        {
          if (e2.Ctrl is System.Windows.Controls.TextBox || e2.Ctrl is System.Windows.Controls.ComboBox || e2.Ctrl is System.Windows.Controls.DatePicker)
          {
            var val = e2.Vcol.TaggedValueLocalAndModelInfo("Placeholder");
            if (!string.IsNullOrEmpty(val))
              MaterialDesignThemes.Wpf.HintAssist.SetHint(e2.Ctrl, val);
            var dataForPlaceholder = e2.Vcol.ViewModelClass.ColumnFromName(e2.Vcol.RuntimeName + "_Placeholder");
            if (dataForPlaceholder != null)
            {
              if (e2.Ctrl is FrameworkElement)
              {
                var b = new System.Windows.Data.Binding(dataForPlaceholder.RuntimeName) { Source = e2.Vcol.ViewModelClass.BindingSource, Mode = System.Windows.Data.BindingMode.OneWay /*, Converter = new Eco.Xaml.PassthroughDebugConverter() */ };
                (e2.Ctrl as FrameworkElement).SetBinding(MaterialDesignThemes.Wpf.HintAssist.HintProperty, b);
              }
            }
          }
        };
This page was edited 82 days ago on 02/10/2024. What links here