I am developing a frame extract from video program. It works well and I can set an interval for the screenshots which are the stored in individual jpg files.
Now I am adding the ability to add things like titles to those jpgs. I have an architecture which creates a TitleEffect which has things like the text, fontsize, color and a in/out point. Now comes the problem.
My first go round is basically - if there is an effect on the video I am extracting frames from then it calls a function within the TitleEffect class which checks the in/out time and if the position of the video falls within those times it returns a usercontrol
which can be added to the children of the Grid which I am using as the basis for the screen capture. Again this works well and I can see the title appear when it should and disappear when it should.
Now the problem. While I can see the title in the window showing the video while doing the frame captures, the resulting jpg does not show the title. If I put the usercontrol into my window thru XAML and rather than add the control in code just
set the datacontext, again I see the title and the jpg shows the title.
I have used Snoop to look at the visual tree and both methods result in the same entries in the tree.
The reason I am trying to do it the code way is that I want to be able to have many different types of effects all using the same architecture. With the present problem that is not feasible.
The code I am using to add the usercontrol in code is:
If currentFileBeingCaptured.Effects.Count > 0 Then
Dim af As AddedEffect = CType(currentFileBeingCaptured.Effects(0), AddedEffect)
Dim tmp As UserControl = af.GetUIElement(theMediaPlayer.Position)
If tmp IsNot Nothing Then
If Not useCurrent Then
If OverLayGrid.Children.Count > 0 Then
OverLayGrid.Children.RemoveAt(0)
End If
tmp.DataContext = af
OverLayGrid.Children.Add(tmp)
Else
testUC.DataContext = af
End If
overlayadded = True
End If
End If
In the above code useCurrent is a variable I created just for testing. True uses the control already existing in the XAML and false will take the usercontrol passed back from the GetUIElement. If I am using the generated usercontrol I check the
count of children in the grid named OverLayGrid and if it is larger than zero (the XAML based usercontrol) it removes it.
As I said above the resulting visual tree is identical in both cases with the only difference being that the XAML based usercontrol has a name.
Any help would be great as I have tried about every permutation I can think of to fix this problem but none has worked.
TIA
Lloyd Sheen
BTW the XAML for the VisualGrid is:
<Grid x:Name="VisualGrid" Grid.Row="1"
Width="{Binding ElementName=sizeCombo, Path=SelectedItem.width, Converter={StaticResource dummyConverter}}"
Height="{Binding ElementName=sizeCombo, Path=SelectedItem.height, Converter={StaticResource dummyConverter}}"><MediaElement x:Name="theMediaPlayer" ScrubbingEnabled="True"
Visibility="Visible"
LoadedBehavior="Manual"
Loaded="MediaElement_Loaded"
MediaOpened="theMediaPlayer_MediaOpened"
Margin="0,5"></MediaElement><Grid x:Name="OverLayGrid"><local:TitleEffectUC x:Name="testUC" Visibility="Visible"></local:TitleEffectUC></Grid></Grid>
Lloyd Sheen