У меня есть следующий конвертер и код, реализованный с целью создания некоторого водяного знака. Этот код работает для TextBlock + TextBox
, но он не для TextBlock + PasswordBox
. Вы знаете, почему этот конвертер не работает?Водяной знак в PasswordBox
XAML
<Helpers:HintConverter x:Key="hint" />
<TextBlock Height="30" Text=" password" Foreground="LightGray" Margin="274,264,278,306" Width="248">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource hint}">
<Binding ElementName="txtPassword" Path="Text.IsEmpty" />
<Binding ElementName="txtPassword" Path="IsFocused" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
<PasswordBox PasswordChanged="PasswordBox_PasswordChanged" Name="txtPassword" BorderThickness="2" Height="30" Margin="273,264,275,306" Background="Transparent">
<PasswordBox.BorderBrush>
<LinearGradientBrush EndPoint="1,1" StartPoint="1,0">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="White" Offset="0.75" />
<GradientStop Color="Green" Offset="0.75" />
<GradientStop Color="#FF0D9ECD" Offset="1" />
</LinearGradientBrush>
</PasswordBox.BorderBrush>
</PasswordBox>
Преобразователь
public class HintConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values[0] is bool && values[1] is bool)
{
bool hasText = !(bool)values[0];
bool hasFocus = (bool)values[1];
if (hasFocus || hasText)
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
попробуйте удалить 'Background = "Transparent"' – Venky
@Venky не работает:/ – Ricardo