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"이 텍스트 상자에 바인딩되지 않고 두 번째 속성 인 IsTextBox가 True로 설정되어 있으면 Passwordbox else Textbox가 자동으로 숨겨집니다.
도움이 필요하십니까? 하여 사용자 컨트롤 내부 바인딩 바인딩 아무 상관이 없습니다 자동 있도록
덕분에, Imdadhusen
좋은 질문 ... –
감사 사가르 Rawal ... 당신이 도움이 될 수 있습니다. – imdadhusen