당신은 변환기를 사용해야한다고 생각합니다. 이
<Style x:Key="LabelStandard" TargetType="Label">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource self},
Path=Content,
Converter={StaticResource LastCharConverter},
ConverterParameter=*}"
Value="True">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
public class LastCharConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
{
return false;
}
string content = value.ToString();
if (content.Length > 0 &&
content[content.Length - 1] == (char)parameter)
{
return true;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
업데이트처럼 뭔가를 시도
당신만큼 당신이 위치를 알고있는 Content
문자열에서 특정 문자에 바인딩 할 수 있습니다.
<Style x:Key="LabelStandard" TargetType="Label">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource self},
Path=(Content)[2]}"
Value="*">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
하지만 당신의 문자열 길이는 내부
[2]
을 결합 할 수 없기 때문에 당신에게 매우 좋은하지 않을 것이다 (나는 경우가 있다고 가정한다) 다를 경우 나는 알고 있어요 어떤 식 으로든 (바인딩 의). 이 외에
, 당신이 자신을
흠 .. 너무 많은 일이 .. 차라리보다 프로그래밍 방식으로 그것을 할 것이라고 지적 당신이 솔루션 뒤에 코드를해야 할 것 같아요 :) lbl.Style = (Style) this.Resources [ "LabelRequired"]; – markmnl
그래도 고마워! – markmnl
업데이트 주셔서 감사합니다 - 너무 가까이에 노력하고 싶어하지만 .. 아무 방법으로 보이지 않습니다 .. – markmnl