8,735
社区成员
发帖
与我相关
我的任务
分享
<StackPanel Grid.Row="1" Orientation="Horizontal">
<RadioButton Content="page1" Checked="Button_Click_1" GroupName="r1" Style="{StaticResource myRadio}" x:Name="radioDef" Margin="5" Width="70" Height="90">
<RadioButton.Background>
<ImageBrush ImageSource="res/1.png"/>
</RadioButton.Background>
</RadioButton>
<RadioButton Content="page2" Checked="Button_Click_2" GroupName="r1" Style="{StaticResource myRadio}" Margin="5" Width="70" Height="90" >
<RadioButton.Background>
<ImageBrush ImageSource="res/2.png"/>
</RadioButton.Background>
</RadioButton>
</StackPanel>
<Frame Grid.Row="2" x:Name="page2frame" NavigationUIVisibility="Hidden" Navigating="NavigationWindow_Navigating"></Frame>
public MainWindow()
{
InitializeComponent();
radioDef.IsChecked = true;
}
//淡入淡出切换
private bool _allowDirectNavigation = false;
private NavigatingCancelEventArgs _navArgs = null;
Page1 page1 = new Page1();
Page2 page2 = new Page2();
int nPage;
private void NavigationWindow_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (Content != null && !_allowDirectNavigation)
{
e.Cancel = true;
_navArgs = e;
this.IsHitTestVisible = false;
DoubleAnimation da = new DoubleAnimation(1, 0.5, new Duration(TimeSpan.FromMilliseconds(200)));
Storyboard.SetTarget(da, page2frame);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
Storyboard bord = new Storyboard();
bord.Children.Add(da);
bord.Completed += FadeOutCompleted;
bord.Begin();
//da.Completed += FadeOutCompleted;
//this.BeginAnimation(OpacityProperty, da);
}
_allowDirectNavigation = false;
}
private void FadeOutCompleted(object sender, EventArgs e)
{
//(sender as AnimationClock).Completed -= FadeOutCompleted;
//(sender as Storyboard).Completed -= FadeOutCompleted;
this.IsHitTestVisible = true;
_allowDirectNavigation = true;
switch (_navArgs.NavigationMode)
{
case NavigationMode.New:
if (_navArgs.Uri == null)
{
//NavigationService.Navigate(_navArgs.Content);
page2frame.Navigate(_navArgs.Content);
}
else
{
//NavigationService.Navigate(_navArgs.Uri);
page2frame.Navigate(_navArgs.Uri);
page2frame.RemoveBackEntry();
}
break;
case NavigationMode.Back:
//NavigationService.GoBack();
page2frame.GoBack();
break;
case NavigationMode.Forward:
//NavigationService.GoForward();
page2frame.GoForward();
break;
case NavigationMode.Refresh:
//NavigationService.Refresh();
page2frame.Refresh();
break;
}
Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
(ThreadStart)delegate()
{
DoubleAnimation da = new DoubleAnimation(0.5,1, new Duration(TimeSpan.FromMilliseconds(200)));
Storyboard.SetTarget(da, page2frame);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
Storyboard bord = new Storyboard();
bord.Children.Add(da);
bord.Begin();
//this.BeginAnimation(OpacityProperty, da);
});
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (nPage != 1)
{
page2frame.Navigate(page1);
nPage = 1;
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if (nPage != 2)
{
page2frame.Navigate(page2);
nPage = 2;
}
}
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Duration="0:0:3" Storyboard.TargetProperty="Opacity" From="0" To="1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid Background="Khaki"/>
</Window>
private void NavigationWindow_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (Content != null && !_allowDirectNavigation)
{
e.Cancel = true;
_navArgs = e;
this.IsHitTestVisible = false;
DoubleAnimation da = new DoubleAnimation(0.3d, new Duration(TimeSpan.FromMilliseconds(300)));
da.Completed += FadeOutCompleted;
this.BeginAnimation(OpacityProperty, da);
}
_allowDirectNavigation = false;
}
private void FadeOutCompleted(object sender, EventArgs e)
{
(sender as AnimationClock).Completed -= FadeOutCompleted;
this.IsHitTestVisible = true;
_allowDirectNavigation = true;
switch (_navArgs.NavigationMode)
{
case NavigationMode.New:
if (_navArgs.Uri == null)
{
NavigationService.Navigate(_navArgs.Content);
}
else
{
NavigationService.Navigate(_navArgs.Uri);
}
break;
case NavigationMode.Back:
NavigationService.GoBack();
break;
case NavigationMode.Forward:
NavigationService.GoForward();
break;
case NavigationMode.Refresh:
NavigationService.Refresh();
break;
}
Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
(ThreadStart)delegate()
{
DoubleAnimation da = new DoubleAnimation(1.0d, new Duration(TimeSpan.FromMilliseconds(200)));
this.BeginAnimation(OpacityProperty, da);
});
}
就是想完全有xaml里面用triger实现