My problem occur when I change the opacity of a textblock from 1.0 to 0.0 while flipping the page. The textblock is in a datatemplate and the opacity is bound to a variable in the datacontext. The behavior I get with the different events are the following:
PageFlipStarted:
Text on page 2 (old page) will disappear before the page has flipped
Text on page 4 (new page) ok i.e. no text is shown at all
PageFlipEnded & PageChanged
Text on page 2 (new page) ok i.e. the text remains
Text on page 4 (new page) will show before it disappears
What I would like is:
Text on page 2 (new page) ok i.e. the text remains
Text on page 4 (new page) ok i.e. no text is shown at all
Any ideas? Preferable without playing around in the visual tree.
(I have been playing around in the visual tree as well but did not manage to solve the problem that way either)
The essential parts of the XAML looks like
<Grid x:Name="LayoutRoot" Background="White"> |
<Grid.Resources> |
<DataTemplate x:Key="LeftPageTemplate"> |
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
</DataTemplate> |
<DataTemplate x:Key="RightPageTemplate"> |
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" |
Opacity="{Binding ElementName=aBook, Path=DataContext.OpacityCollection[1]}" |
Visibility="{Binding ElementName=aBook, Path=DataContext.VisabilityCollection[1]}"/> |
</DataTemplate> |
</Grid.Resources> |
<telerikNavigation:RadBook PageChanged="aBook_PageChanged" |
PageFlipStarted="aBook_PageFlipStarted" |
PageFlipEnded="aBook_PageFlipEnded" |
LeftPageTemplate="{StaticResource LeftPageTemplate}" |
RightPageTemplate="{StaticResource RightPageTemplate}" |
ItemsSource="{Binding TextCollection}" |
x:Name="aBook"/> |
</Grid> |
And the C#
public partial class MainPage : UserControl |
{ |
PageData pg; |
public MainPage() |
{ |
InitializeComponent(); |
pg = new PageData(); |
} |
private void UserControl_Loaded(object sender, RoutedEventArgs e) |
{ |
aBook.DataContext = pg; |
} |
private void aBook_PageChanged(object sender, Telerik.Windows.RadRoutedEventArgs e) |
{ |
/* |
*Page 2 ok |
*Text on page 4 will show before it disapears |
*/ |
// pg.OpacityCollection[1] = 0.0; |
// pg.VisabilityCollection[1] = Visibility.Collapsed; |
} |
private void aBook_PageFlipEnded(object sender, Telerik.Windows.Controls.PageFlipEventArgs e) |
{ |
/* |
*Page 2 ok |
*Text on page 4 will show before it disapears |
*/ |
//pg.OpacityCollection[1] = 0.0; |
// pg.VisabilityCollection[1] = Visibility.Collapsed; |
} |
private void aBook_PageFlipStarted(object sender, Telerik.Windows.Controls.PageFlipEventArgs e) |
{ |
/* |
*Page 4 ok |
*Text on page 2 will disapear before the page has flipped |
*/ |
pg.OpacityCollection[1] = 0.0; |
// pg.VisabilityCollection[1] = Visibility.Collapsed; |
} |
} |
public class PageData |
{ |
public ObservableCollection<string> TextCollection { get; set; } |
public ObservableCollection<double> OpacityCollection { get; set; } |
public ObservableCollection<Visibility> VisabilityCollection { get; set; } |
public PageData() |
{ |
TextCollection = new ObservableCollection<string>() { "Page 1", "Page 2", "Page 3", "Page 4" }; |
OpacityCollection = new ObservableCollection<double>() { 1.0, 1.0 }; |
VisabilityCollection = new ObservableCollection<Visibility>() { Visibility.Visible, Visibility.Visible }; |
} |
} |
} |