0
當我進入文成DoubleUpDown
控制,復位和控制以紅色突出顯示。 它看起來像這樣:如何使默認的DoubleUpDown驗證樣式?
如何申請相同的風格爲負數?
我通過創建PositiveNumberToColorConverter
做到這一點,並將其應用巫邊界:
public class PositiveNumberToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value is int?)
{
var intValue = (int?)value;
if (intValue == null)
return Brushes.Transparent;
else if (intValue.HasValue&&intValue.Value>=0)
return Brushes.Transparent;
else if(intValue.HasValue==false)
return Brushes.Transparent;
return Brushes.Red;
}
return Brushes.Red;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<Border
Grid.Column="0"
BorderThickness="1"
Background="Transparent"
BorderBrush="{Binding ObjectViewModel.Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource positiveNumberConverter}}"
IsEnabled="{Binding ObjectViewModel.IsEnabled,Mode=TwoWay,TargetNullValue=False,FallbackValue=False,UpdateSourceTrigger=PropertyChanged}"
>
<xcd:DoubleUpDown
HorizontalAlignment="Stretch"
Margin="5"
Grid.Column="0"
Minimum="0"
Height="{Binding ElementName=tbName,Path=Height}"
Width="Auto"
IsEnabled="{Binding ObjectViewModel.IsEnabled,Mode=TwoWay,TargetNullValue=False,FallbackValue=False,UpdateSourceTrigger=PropertyChanged}"
Text="{Binding ObjectViewModel.Value,Mode=TwoWay,UpdateSourceTrigger=LostFocus}" >
<xcd:DoubleUpDown.Resources>
<Style TargetType="Popup">
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</xcd:DoubleUpDown.Resources>
</xcd:DoubleUpDown>
</Border>
但是,它看起來像這樣:
如何使這樣在負數的輸入它突出顯示在第一張圖片上(默認情況下如何實現文本輸入)?
沒有。我會立即嘗試 –