我需要找到在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