2

アドベンチャー ゲームでの移動のように、ラベルのグリッドをマウスの位置に移動しようとしています。理想的には、途中でそれらを削除して再描画します。しかし、今のところ、int を厚さまたは pointtoscreen に変換する方法を理解したいだけです。

これまでのところ、私は持っています:

player.XMove =  (int)Mouse.GetPosition(Application.Current.MainWindow).X;
player.YMove = (int)Mouse.GetPosition(Application.Current.MainWindow).Y;

player.XMove と player.YMove を太さに変換してラベル付きグリッドの余白として保存してみました。変換する際に問題が発生しました。それで、変換を手伝ってくれる人はいますか?また、ポイントを変換するためのより良いラベル/グリッド属性はありますか

追記:画像リンク追加。

http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps51f2359f.jpg

編集: 現在のコードと XAML を追加しました。私はまだそれをいじる機会がありませんでした。

これは私の現在のコードがどのように見えるかです:

public class User
    {
        private int fed;
        public int Fed
        {
            get
            {
                return fed;
            }
            set
            {
                fed = 5;
            }
        }

        private bool visible;
        public bool Visible
        {
            get
            {
                return visible;
            }
            set
            {
                visible = value;
            }
        }

        private int xMove;
        public int XMove
        {
            get
            {
                return xMove;
            }
            set
            {
                xMove = value;
            }
        }

        private int yMove;
        public int YMove
        {
            get
            {
                return yMove;
            }
            set
            {
                yMove = value;
            }
        }

    }

最終的には、ユーザー クラスとロケーション クラスの間にHas Aorを追加します (未掲載)。Uses A

メインウィンドウの私のコード:

public partial class MainWindow : Window
    {
        User player = new User();
        ThicknessConverter perimeter = new ThicknessConverter();
        public MainWindow()
        {
            InitializeComponent();

        }

        private void Hansel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
             Hansel.Visibility = Visibility.Visible;
        }

        private void Hansel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            player.XMove =  (int)Mouse.GetPosition(Application.Current.MainWindow).X;
            player.YMove = (int)Mouse.GetPosition(Application.Current.MainWindow).Y;

        }

        private void southRectangle_IsHitTestVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }


    }

bool を可視性に変換する作業も行っていますが、XAML がそこにあったコンバーターの名前空間を見つけられないというエラーが発生しました。

XAML は次のようになります。

<Window x:Class="HanselAndGretalDisplay.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:HanselAndGretalDisplay"
        Title="MainWindow" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <Grid>
        <Grid.Resources>
            <local:BoolToVisibleOrHidden x:Key="BoolToVisConverter"/>
        </Grid.Resources>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="179,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="79,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,119,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,19,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="698,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="698,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,94,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="698,44,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="723,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="623,69,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,119,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,19,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="104,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="154,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="179,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="79,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,450,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="129,350,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="623,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="623,425,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="623,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="673,375,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="698,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="598,400,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,450,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="648,350,0,0" VerticalAlignment="Top" Foreground="#FF1B4015" Width="25" Background="#FF1B4015" BorderBrush="Black" BorderThickness="3" Height="25"/>
        <Grid x:Name="Hansel" IsVisibleChanged="Hansel_IsVisibleChanged" MouseLeftButtonDown="Hansel_MouseLeftButtonDown">
            <Label Content="Label" HorizontalAlignment="Left" Margin="398,218,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="398,243,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="398,268,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="373,243,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="423,243,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="413,293,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="383,293,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="439,268,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Label Content="Label" HorizontalAlignment="Left" Margin="353,268,0,0" VerticalAlignment="Top" Foreground="#FFFFE2C5" Width="25" Background="#FFFFE2C5" BorderBrush="Black" BorderThickness="3" Height="25"/>
            <Rectangle x:Name="southRectangle" HorizontalAlignment="Left" Height="79" Margin="209,425,0,0" VerticalAlignment="Top" Width="383" IsHitTestVisibleChanged="southRectangle_IsHitTestVisibleChanged"/>
            <Rectangle x:Name="northRectangle" HorizontalAlignment="Left" Height="79" Margin="209,0,0,0" VerticalAlignment="Top" Width="412"/>
            <Rectangle x:Name="westRectangle" HorizontalAlignment="Left" Height="202" Margin="0,145,0,0" VerticalAlignment="Top" Width="133"/>
            <Rectangle x:Name="eastRectangle" HorizontalAlignment="Left" Height="202" Margin="627,145,0,0" VerticalAlignment="Top" Width="133"/>
        </Grid>
    </Grid>
</Window>

プログラムで XAML オブジェクトを生成し、最初の場所に割り当てる簡単な方法があれば、このプロジェクトで長期的には理想的ですが、今のところあまり心配していません。

4

1 に答える 1