帧中的动画问题 [英] Animation Problem in Frame
问题描述
在我的窗口中,当我单击该按钮时,我有一个按钮.当我单击尝试最大化窗口并调整窗口大小"时,框架的宽度不会改变.
In my Window i have a button when i click that button Pages added in the Frame. when i click the when i try to maximize window and resize window, frame width will not changing.
当窗口最大化并调整窗口大小时,我想更改其大小.请帮助我一个人
I want to change the size when it maximize and resize window . Please heip me any one
这是我的完整代码
使用系统;
使用System.Collections.Generic;
using System.Collections.Generic;
使用System.Linq;
using System.Linq;
使用System.Text;
using System.Text;
使用System.Windows;
using System.Windows;
使用System.Windows.Controls;
using System.Windows.Controls;
使用System.Windows.Data;
using System.Windows.Data;
使用System.Windows.Documents;
using System.Windows.Documents;
使用System.Windows.Input;
using System.Windows.Input;
使用System.Windows.Media;
using System.Windows.Media;
使用System.Windows.Media.Imaging;
using System.Windows.Media.Imaging;
使用System.Windows.Navigation;
using System.Windows.Navigation;
使用System.Windows.Shapes;
using System.Windows.Shapes;
使用System.Windows.Media.Animation;
using System.Windows.Media.Animation;
使用System.Windows.Threading;
using System.Windows.Threading;
使用System.Threading;
using System.Threading;
使用DevExpress.Xpf.Core;
using DevExpress.Xpf.Core;
命名空间FrameSlider
namespace FrameSlider
{
///< summary>
/// <summary>
///MainWindow.xaml的交互逻辑
/// Interaction logic for MainWindow.xaml
///</summary>
/// </summary>
公共局部类MainWindow:Window
public partial class MainWindow : Window
{
{
情节提要myWidthAnimatedButtonStoryboard = new情节提要();
Storyboard myWidthAnimatedButtonStoryboard = new Storyboard();
框架objframe;
Frame objframe;
TabControl objtab =新的TabControl();
TabControl objtab = new TabControl();
公共TabItem objTabItem;
public TabItem objTabItem;
int i = 0;
int i = 0;
ProgressBar objprogress;
ProgressBar objprogress;
窗口w;
Window w;
私人委托void simpleDelegate();
private delegate void simpleDelegate();
公共MainWindow()
public MainWindow()
{
{
InitializeComponent();
InitializeComponent();
objtab.Margin = new Thickness(7,35,7,7);
objtab.Margin = new Thickness(7, 35, 7, 7);
}
}
私有void button1_Click(对象发送者,RoutedEventArgs e)
private void button1_Click(object sender, RoutedEventArgs e)
{
{
objTabItem = new TabItem();
objTabItem = new TabItem();
objframe = new Frame();
objframe = new Frame();
objtab.Items.Add(objTabItem);
objtab.Items.Add(objTabItem);
如果(i == 0)
if (i == 0)
{
{
mygrid.Children.Add(objtab);
mygrid.Children.Add(objtab);
}
}
objTabItem.IsSelected = true;
objTabItem.IsSelected = true;
线程thread4 = new Thread(()=>
Thread thread4 = new Thread(() =>
{
{
w = new Window();
w = new Window();
w.WindowState = WindowState.Normal;
w.WindowState = WindowState.Normal;
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
w.Height = 40;
w.Height = 40;
w.Width = 300;
w.Width = 300;
w.ResizeMode = ResizeMode.NoResize;
w.ResizeMode = ResizeMode.NoResize;
w.WindowStyle = WindowStyle.None;
w.WindowStyle = WindowStyle.None;
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
objprogress = new ProgressBar();
objprogress = new ProgressBar();
objprogress.IsIndeterminate = true;
objprogress.IsIndeterminate = true;
w.Content = objprogress;
w.Content = objprogress;
w.Show();
w.Show();
w.Closed + =(sender2,e2)=>
w.Closed += (sender2, e2) =>
w.Dispatcher.InvokeShutdown();
w.Dispatcher.InvokeShutdown();
System.Windows.Threading.Dispatcher.Run();
System.Windows.Threading.Dispatcher.Run();
});
});
thread4.SetApartmentState(ApartmentState.STA);
thread4.SetApartmentState(ApartmentState.STA);
thread4.Start();
thread4.Start();
System.Threading.Thread线程=新的System.Threading.Thread(
System.Threading.Thread thread = new System.Threading.Thread(
新的System.Threading.ThreadStart(
new System.Threading.ThreadStart(
委托()
delegate()
{
{
System.Windows.Threading.DispatcherOperation
System.Windows.Threading.DispatcherOperation
dispatcherOp = objframe.Dispatcher.BeginInvoke(
dispatcherOp = objframe.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
System.Windows.Threading.DispatcherPriority.Normal,
新动作(
new Action(
委托()
delegate()
{
{
Thread.Sleep(4000);
Thread.Sleep(4000);
objframe.Background = Brushes.Red;
objframe.Background = Brushes.Red;
objframe.NavigationUIVisibility = NavigationUIVisibility.Hidden;
objframe.NavigationUIVisibility = NavigationUIVisibility.Hidden;
如果(i == 0)
if (i == 0)
{
{
objframe.Navigate(new Page1());
objframe.Navigate(new Page1());
i = i + 1;
i = i + 1;
objTabItem.Header ="First";
objTabItem.Header = "First";
}
}
否则(i == 1)
else if (i == 1)
{
{
objframe.Navigate(new Page2());
objframe.Navigate(new Page2());
i = i + 1;
i = i + 1;
objTabItem.Header ="Secound";
objTabItem.Header = "Secound";
}
}
否则(i == 2)
else if (i == 2)
{
{
objframe.Navigate(new Page1());
objframe.Navigate(new Page1());
objTabItem.Header ="First";
objTabItem.Header = "First";
}
}
objTabItem.Content = objframe;
objTabItem.Content = objframe;
thread4.Abort();
thread4.Abort();
DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
myDoubleAnimation1.From = 0;
myDoubleAnimation1.From = 0;
myDoubleAnimation1.To =宽度;
myDoubleAnimation1.To = Width;
myDoubleAnimation1.Duration = new Duration(TimeSpan.FromMilliseconds(1500));
myDoubleAnimation1.Duration = new Duration(TimeSpan.FromMilliseconds(1500));
objframe.BeginAnimation(WidthProperty,myDoubleAnimation1);
objframe.BeginAnimation(WidthProperty, myDoubleAnimation1);
//objtab.SizeChanged + =新的SizeChangedEventHandler(objtab_SizeChanged);
//objtab.SizeChanged += new SizeChangedEventHandler(objtab_SizeChanged);
}
}
));
));
}
}
));
));
thread.Start();
thread.Start();
}
}
推荐答案
由于动画"将帧的宽度设置为硬值(窗口宽度"值).不能通过MainWindow的大小更改来更改它.
Since the Frame's Width is set by the Animation to a hard value (the window Width value). It cannot be changed by the MainWindow size changing.
请参考此操作方法,将值重新设置为Width属性: http://msdn.microsoft.com/en-us/library/aa970493.aspx
Please refer to this HOW TO to set the value back to the Width property: http://msdn.microsoft.com/en-us/library/aa970493.aspx
并如下更改您的内容:
DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
myDoubleAnimation1.From = 0;
myDoubleAnimation1.To = Width;
myDoubleAnimation1.Duration = new Duration(TimeSpan.FromMilliseconds(1500));
myDoubleAnimation1.Completed+=(o, arg)=>{
objframe.BeginAnimation(WidthProperty, null);
};
objframe.BeginAnimation(WidthProperty, myDoubleAnimation1);
这篇关于帧中的动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!