我如何通过xaml触发器做到这一点? 如何在xaml中翻转TextBox?
回答
如果要生成graphicaly,请在Blend中打开项目。
打开触发选项卡(第三个选项卡)
+事件
在当部分中,选择出了名的文本框,并在事件LostFocus(或的GotFocus)
点击的+右“是提出了”以创建故事板
在对象和时间线窗口中,选择文本框,并选择在200毫秒的点(2线右侧)
然后在属性窗口,变换部,应用旋转:
对于文本框在属性窗口,LayoutTransform部分,编辑:
-r的中心浮选在第五个标签(0,0),在第二个选项卡(-90)
这里旋转
-Angle是生成的代码:
<Window x:Class="DemoRotateWithTrigger.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Storyboard x:Key="OnLostFocus1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="textboxToBeRotated">
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-90"/>
</DoubleAnimationUsingKeyFrames>
<PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="textboxToBeRotated">
<EasingPointKeyFrame KeyTime="0:0:0.2" Value="0,0"/>
</PointAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnGotFocus1">
<PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="textboxToBeRotated">
<EasingPointKeyFrame KeyTime="0:0:0.2" Value="0,0"/>
</PointAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="textboxToBeRotated">
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="UIElement.LostFocus" SourceName="textboxToBeRotated">
<BeginStoryboard Storyboard="{StaticResource OnLostFocus1}"/>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.GotFocus" SourceName="textboxToBeRotated">
<BeginStoryboard x:Name="OnGotFocus1_BeginStoryboard" Storyboard="{StaticResource OnGotFocus1}"/>
</EventTrigger>
</Window.Triggers>
<Grid>
<TextBox x:Name="textboxToBeRotated" HorizontalAlignment="Left" Height="23" Margin="138,158,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0,0">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<Button Content="Button" HorizontalAlignment="Left" Margin="75,219,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
好运
集RenderTransformOrigin = new Point(0, 0)
并设置初始RenderTransform = new RotateTransform(-90)
在Loaded
窗口的事件,然后将其设置为GotFocus
0
和LostFocus
再次-90
。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.TextBox1.RenderTransformOrigin = new Point(0, 0);
this.TextBox1.RenderTransform = new RotateTransform(-90);
}
private void TextBox1_GotFocus(object sender, RoutedEventArgs e)
{
this.TextBox1.RenderTransform = new RotateTransform(0);
}
private void TextBox1_LostFocus(object sender, RoutedEventArgs e)
{
this.TextBox1.RenderTransform = new RotateTransform(-90);
}
记得在窗口中有另一个控件来测试LostFocus
。
谢谢它的工作原理,但我要求xaml触发器。 –
问题是“我怎样才能在xaml中翻转TextBox?”。这个答案是C#。 –
- 1. XAML页面翻转扭曲
- 2. TextBox HideSelection in XAML
- 3. 如何在XAML中创建TextBox样式,以便TextBox只接受数字
- 4. 如何在Microsoft Report中旋转TextBox?
- 5. 在GridView中访问TextBox文本(C#/ XAML)
- 6. 如何在.NET中翻转/旋转PrintDocument?
- 7. 如何在TextBox中保存用户推测值? (WPF,XAML)
- 8. 如何在XAML中注入转换器
- 9. WinRT XAML Textbox,SelectionStart和CR/LF
- 10. 如何在vim中翻转窗口?
- 11. 如何在C++中翻转cv :: mat?
- 12. 如何在iPhone SDK中翻转按钮?
- 13. 如何在SQL Server中翻转一点?
- 14. 如何在OpenGL中翻转图像?
- 15. 如何在Android中翻转ImageView?
- 16. 如何读取XAML中的TextBox前景/背景属性?
- 17. 如何翻转UIImageView?
- 18. 如何翻转QImage
- 19. 如何翻转jcombobox?
- 20. 如何翻转flash.media.Video?
- 21. 如何在翻页前后翻转翻页书本
- 22. 在XAML中如何说:默认的宽度和高度,例如TextBox
- 23. 如何在黑莓中翻译/翻转查看/管理器?
- 24. 使用绑定在XAML中的TextBox中的点
- 25. 在Android中翻页/翻转动画?
- 26. 如何将DatePicker和TextBox信息从XAML导入Powershell变量?
- 27. AS3 - 如何翻转吐温
- 28. 如何做翻转板?
- 29. 如何翻转堆叠?
- 30. 如何翻转Android图像
谢谢,干得不错。 –