本文介绍了获取ItemsControl的子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi i would like to add different style to my txtTitle using datatrigger. However i do not know how to get the child 
of my ChildrenList in my datatrigger. The child are all using the same name - txtTitle and txtSupportText.


  <DataTemplate DataType="{x:Type dm:QualityElementViewModel}">
      <StackPanel>
        <TextBox x:Name="txtTitle" Text="{Binding Path=Title,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
             Background="Blue" FontWeight="Bold" Foreground="White" Style="{DynamicResource normalStyle}" />
        <TextBox x:Name="txtSupportText" Text="{Binding Path=SupportingText,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
          Style="{StaticResource normalStyle}" AcceptsReturn="True" />
        <ItemsControl ItemsSource="{Binding ChildrenList}"/>
      </StackPanel>
      
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=IsInEditMode}" Value="True">
          <Setter TargetName="txtSupportText" Property="Style" Value="{StaticResource editingStyle}"/>
          <Setter TargetName="txtTitle" Property="Style" Value="{StaticResource editingStyle}"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding Title}" Value="Paragraph">
          <Setter TargetName="txtTitle" Property="Visibility" Value="Collapsed" />
        </DataTrigger>
		// i want to create this, how to detect the child in the binding?	
		<DataTrigger Binding="{Binding ChildrenList.Child}">
          <Setter TargetName="txtTitle" Property="Style" Value="{StaticResource alignCenter}" />
        </DataTrigger>
		<DataTrigger Binding="{Binding ChildrenList.Child.Child}">
          <Setter TargetName="txtTitle" Property="Style" Value="{StaticResource alignRight}" />
        </DataTrigger>

</DataTemplate.Triggers> </DataTemplate>

</DataTemplate.Triggers> </DataTemplate>

推荐答案


这篇关于获取ItemsControl的子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:16