我需要找到在XAML特定的控制代码操作来改变背景。查找文本块控制彩色
我的问题是,无法找到具体的控制。
我试图.FindByName(文字块),并与visualtreehelper。还试图在代码txtVeranderkleur中键入它,但系统不知道控制,因为它在孩子们内我猜。没有为我工作。
我需要找到 “txtVeranderkleur”。所以我可以更改代码中的颜色。
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="0,0,0,28" Orientation="Horizontal">
<Border Background="#EE2E24" CornerRadius="15,15,15,15" Width="450" Margin="15,15,15,15">
<TextBlock x:Name="Events" TextWrapping="Wrap" Text="Evenementen" Style="{StaticResource subtitle}" Margin="15,15,15,15"/>
</Border>
</StackPanel>
<ListBox Grid.Row="1" Margin="12,-15,0,12" x:Name="lbDagprogrammaInfo" SelectionChanged="lbDagprogrammaInfo_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="15,0,0,17">
<Border Width="70" Height="70" BorderBrush="#EE2E24" Background="#EE2E24" BorderThickness="3" CornerRadius="3,3,3,3" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBlock Width="70" Height="70" Text="{Binding LineTeller}" Style="{StaticResource contentRect}"></TextBlock>
</Border>
<StackPanel Orientation="Horizontal" Margin="8,0,0,0">
**<TextBlock x:Name="txtVeranderkleur" Style="{StaticResource contentText}">
<Run Text="{Binding LineUur}"></Run>
<Run Text="{Binding LineNaam}"></Run>
</TextBlock>**
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Width="480" Height="80" Background="Black" Grid.Row="2">
<Image x:Name="imgSponsor" Source="{Binding LineSponsorFoto}" Height="80" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3" />
</StackPanel>
</Grid>
不为我工作。我没有找到你的containerfromindex或getchild的我的txtVeranderkleur。但是,无论如何,谢谢 – 2013-05-07 14:28:06
@SigfridMaenhout你必须使用ContainerFromIndex来获取ListBoxItem,然后执行VisualTreeHelper.GetChild多次进入文本块。在ListBoxItem上调用GetChild会得到一个Border,在Border上调用GetChild会为你提供一个ContentControl,等等。 – Murkaeus 2013-05-07 15:45:21
啊哈知道我明白。谢谢。 ;) – 2013-05-08 09:21:20