Note that there are some explanatory texts on larger screens.

plurals
  1. POBindingMode.TwoWay does not work with UserControl (not update source property)
    primarykey
    data
    text
    <p><strong>I have created Custom User Control which contain TextBox and PasswordBox. it is binding completely work but when i changed any value inside TextBox or PasswordBox of user control then my source property does not getting refreshed.</strong></p> <p><em>Following are the code for my Custom User Control</em></p> <p><strong>RestrictedBox.xaml</strong></p> <pre><code>&lt;UserControl.Resources&gt; &lt;Converters:EnumToVisibilityConverter x:Key="enumToVisibilityConverter" /&gt; &lt;Converters:EnumToVisibilityConverterReverse x:Key="enumToVisibilityConverterReverse" /&gt; &lt;/UserControl.Resources&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent" &gt; &lt;StackPanel&gt; &lt;TextBox x:Name="txtTextBox" Width="50" Height="25" /&gt; &lt;PasswordBox x:Name="txtPasswordBox" Width="50" Height="25" /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p><strong>RestrictedBox.xaml.cs</strong></p> <pre><code>public partial class RestrictedBox : UserControl { public RestrictedBox() { InitializeComponent(); txtTextBox.SetBinding(TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }); txtTextBox.SetBinding(TextBox.VisibilityProperty, new Binding("Type") { Source = this, Converter = new EnumToVisibilityConverter() }); txtPasswordBox.SetBinding(PasswordBox.PasswordProperty, new Binding { Source = this, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }); txtPasswordBox.SetBinding(TextBox.VisibilityProperty, new Binding("Type") { Source = this, Converter = new EnumToVisibilityConverterReverse() }); } public string Value { get { return (string)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(RestrictedBox), new PropertyMetadata("", ValueChanged)); private static void ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { } public Mode Type { get { return (Mode)GetValue(TypeProperty); } set { SetValue(TypeProperty, value); } } public static readonly DependencyProperty TypeProperty = DependencyProperty.Register("Type", typeof(Mode), typeof(RestrictedBox), new PropertyMetadata(Mode.Text, TypeChanged)); private static void TypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { } } </code></pre> <p><em>Following are the code for LoginView where i have used my custom User Control (RestrictedBox).</em></p> <p><strong>LoginView.xaml</strong></p> <pre><code>&lt;control:RestrictedBox Type="Text" Value="{Binding Path=UserName}" /&gt; </code></pre> <p><strong>LoginView.xaml.cs</strong></p> <pre><code> [Export(typeof(LoginView))] [PartCreationPolicy(CreationPolicy.NonShared)] public partial class LoginView : UserControl, IPageTitle { #region Constuctors public LoginView() { InitializeComponent(); } [Import] public LoginViewModel ViewModel { get { return this.DataContext as LoginViewModel; } set { DataContext = value; } } #endregion } </code></pre> <p><strong>LoginViewModel.cs</strong></p> <pre><code>[Export] [PartCreationPolicy(CreationPolicy.NonShared)] public class LoginViewModel : INotifyPropertyChanged, IRegionMemberLifetime { private string _UserName = ""; public string UserName { get { return _UserName; } set { _UserName = value; OnPropertyChanged("UserName"); } } [ImportingConstructor] public LoginViewModel(IEventAggregator eventAggregator, IRegionManager regionManager) { } } </code></pre> <p><strong>Please help me to resolved this because i am trying to resolve since last 1.5 days without any luck.</strong></p> <p><strong>Your comments and suggestions would be highly appreciated.</strong></p> <p><strong>Note:-</strong> I am able to bind value of the UserName to TextBox but i update TextBox and click on submit i couldn't getting updated value from TextBox.</p> <p>Thanks,</p> <p>Imdadhusen</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload