TextBoxとPasswordBoxを含むユーザーコントロールを作成しました。 RestrictedBox.xamlメインビューからUserControlをバインドできません
<UserControl.Resources>
<Converters:BoolToVisibilityConverter x:Key="boolToVisConverter" />
<Converters:BoolToVisibilityConverter x:Key="boolToVisConverterReverse" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" Width="Auto">
<StackPanel Margin="5,5,5,5">
<TextBox Text="{Binding TextValue}" Visibility="{Binding IsTextBox,Converter={StaticResource boolToVisConverter}}" BorderBrush="Green" />
<PasswordBox Password="{Binding TextValue}" Visibility="{Binding IsTextBox,Converter={StaticResource boolToVisConverterReverse}}" BorderBrush="Red" />
</StackPanel>
</Grid>
RestrictedBox.xaml.cs
public partial class RestrictedBox : UserControl
{
public RestrictedBox()
{
InitializeComponent();
}
public string TextValue
{
get { return (string)GetValue(TextValueProperty); }
set { SetValue(TextValueProperty, value); }
}
public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register("TextValue", typeof(string), typeof(RestrictedBox), new PropertyMetadata(default(string)));
public bool IsTextBox
{
get { return (bool)GetValue(IsTextBoxProperty); }
set { SetValue(IsTextBoxProperty, value); }
}
public static readonly DependencyProperty IsTextBoxProperty = DependencyProperty.Register("IsTextBox", typeof(bool), typeof(RestrictedBox), new PropertyMetadata(default(bool)));
}
は、今私は
<control:RestrictedBox TextValue="Imdadhusen" IsTextBox="True" />
今私のLoginView.xamlページにユーザーコントロールの上に追加しました私はTextValue = "Imdadhusen"はテキストボックスにバインドされず、2番目のプロパティIsTextBoxはTrueに設定されます。つまり、Passwordbox else Textboxが自動的に非表示になります。
ご協力いただければ幸いです!
おかげで、ユーザーコントロール内の結合がバインドするために何かを持っていないので、 Imdadhusen
...良い質問... –
おかげサーガルラワルあなたにこの助けとなる可能性があります。 – imdadhusen