У меня есть одна главная страница и один пользовательский элемент управления, и у меня есть одна кнопка в пользовательском элементе управления с событиями для поворота. События запускаются для поворота, но не из центра, а из угла. Но я хочу повернуть сетку с центром.Пользователь может легко поворачивать видение под другим углом. Я пытался создать одно приложение для построения карты. Поэтому пользователь может поворачивать пол, чтобы видеть под другим углом. Помогите, пожалуйста, решить эту проблему. Мой пользовательский элемент управления Xamal:
<UserControl x:Class="Floorsreen.FloorUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="600" Background="Yellow" >
<Grid Width="600" Height="600" Background="Yellow" >
<Grid Width="500" Height="500" Background="Wheat" Name="my_grid">
<Grid.RenderTransform>
<RotateTransform x:Name="transform" />
</Grid.RenderTransform>
<Grid HorizontalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="20" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="20" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
</Grid>
</Grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="516,582,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</UserControl>
My UserControl code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace Floorsreen
{
/// <summary>
/// Interaction logic for FloorUserControl.xaml
/// </summary>
public partial class FloorUserControl : UserControl
{
public FloorUserControl()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Storyboard storyboard = new Storyboard();
DoubleAnimation rotateAnimation = new DoubleAnimation()
{
From = 0,
To = 90,
Duration = new Duration(TimeSpan.FromSeconds(10.0))
};
Storyboard.SetTarget(rotateAnimation, my_grid);
Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
storyboard.Children.Add(rotateAnimation);
storyboard.Begin();
}
}
}
И моя главная страница xamal:
<Window x:Class="Floorsreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace:Floorsreen"
Title="MainWindow" Height="800" Width="1000">
<Window.Resources>
</Window.Resources>
<Grid>
<view:FloorUserControl />
</Grid>
</Window>