WPF Changing Controls within a data template?
so now that I can access controls hidden within nested datatemplates, it seems that I cannot change their values. For instance I have the code (granted to me graciously by a Stack overflow member)
<Grid Name="mainGrid">
<Grid.Resources>
<DataTemplate x:Key="frontTemplate" >
<StackPanel x:Name="noWork">
<Image Source="Images/1.png" Stretch="Fill" Width="72" Height="96" x:Name="FrontFace" HorizontalAlignment="Left" VerticalAlignment="Top"></Image>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="flipItemTemplate">
<Grid Width="200" Height="200">
<Border x:Name="frontHost" Background="Transparent">
<ContentPresenter Name="contentPresenter" Content="{Binding}" ContentTemplate="{StaticResource frontTemplate}" />
</Border>
</Grid>
</DataTemplate>
</Grid.Resou开发者_StackOverflow中文版rces>
</Grid>
And although I can get TO the image in that second template (frontFace) I can't get the source to change. I can get a new bitmap, and load it without error, but the image does not change. If I put an image control in the XAML outside of the datatemplate and load it with my bitmap code there, it works fine. This leads me to believe that the template can't redraw itself after its been applied... BUT I can't get access to its internal elements until its been applied... so how in the heck do I dynamically set up elements in a template before its been applied?
The template duplicates its content. You are accessing the Image
element of your template, not the one instanciated in the content presenter.
精彩评论