2016-07-23 4 views
0

У меня есть Expander, который будет содержит список элементов, это структура:Изменить TextBlock Text из ITEMCOUNT через XAML

<Expander IsExpanded="True" Background="#4F4F4F"> 
    <Expander.Header> 
    <StackPanel Orientation="Horizontal" Height="22"> 
     <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" FontSize="22" VerticalAlignment="Bottom" /> 
     <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Orange" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" /> 
     <TextBlock Text=" match" FontSize="22" Foreground="White" FontStyle="Italic" VerticalAlignment="Bottom" /> 
    </StackPanel> 
    </Expander.Header> 
    <ItemsPresenter /> 
</Expander> 

То, что я хочу добиться того, что когда ItemCount второго TextBlock является > 1 текст из последнего TextBlock match автоматически изменится в matches это возможно через xaml? Благодарю.

ответ

1

Вы можете установить TextBlock Text в стиле

<StackPanel Orientation="Horizontal" Height="22"> 
    <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" FontSize="22" VerticalAlignment="Bottom" /> 
    <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Orange" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" /> 
    <TextBlock FontSize="22" Foreground="White" FontStyle="Italic" VerticalAlignment="Bottom" > 
     <TextBlock.Style> 
      <Style TargetType="{x:Type TextBlock}"> 
       <Setter Property="Text" Value=" matches" /> 
       <Style.Triggers> 
        <DataTrigger Binding="{Binding ItemCount}" Value="1"> 
         <Setter Property="Text" Value=" match" /> 
        </DataTrigger> 
       </Style.Triggers> 
      </Style> 
     </TextBlock.Style> 
    </TextBlock> 
</StackPanel> 
+0

Wow очень интересное решение, спасибо большое за это :) Хорошего дня! – Heisenberg

0

Это менее значимо для этого в чистом Xaml.

Вы можете написать конвертер для этого

<TextBlock Text="{Binding ItemCount, Converter={StaticResource ItemCountConverter}}" /> 

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     return (int)value > 1 ? "matches" : "match"; 
    } 
Смежные вопросы