Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Re: CellEditor with PasswordBox

  •  05-27-2008, 8:52 AM

    Re: CellEditor with PasswordBox

    You can try something like this:

    <Grid>
    <Grid.Resources>
     <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                        Source="{Binding Source={x:Static Application.Current},
                                                  Path=Orders}">
     </xcdg:DataGridCollectionViewSource>

     <local:StringToPasswordConverter x:Key="stringToPasswordConverter" />
     
     <xcdg:CellEditor x:Key="passwordEditor">
        <xcdg:CellEditor.EditTemplate>
           <DataTemplate>
              <xcdg:AutoSelectTextBox Text="{xcdg:CellEditorBinding}" />
           </DataTemplate>
        </xcdg:CellEditor.EditTemplate>
     </xcdg:CellEditor>

     <DataTemplate x:Key="passwordDataTemplate">
        <TextBlock Text="{Binding Converter={StaticResource stringToPasswordConverter}}" />
     </DataTemplate>


    </Grid.Resources>
    <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}">
     <xcdg:DataGridControl.Columns>
        <xcdg:Column FieldName="ShipCountry"                      
                     CellContentTemplate="{StaticResource passwordDataTemplate}"
                     CellEditor="{StaticResource passwordEditor}"/>
     </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </Grid>

    CONVERTER
    --------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;

    namespace Xceed.Wpf.Documentation
    {
      public class StringToPasswordConverter: IValueConverter
      {
        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
          string password = string.Empty;
          if( value is string )
          {
            foreach( char s in ( string )value )
            {
              password += "*";
            }
          }

          return password;
        }

        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
          throw new NotImplementedException();
        }
      }
    }

     


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View Complete Thread
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.