Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:19+00:00 2026-05-23T12:09:19+00:00

XAML code is below <Window x:Class=DenemeWpfApplication1.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> <Grid> <DockPanel Width=Auto

  • 0

XAML code is below

<Window x:Class="DenemeWpfApplication1.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">
    <Grid>
        <DockPanel Width="Auto"
                   VerticalAlignment="Stretch"
                   Height="Auto"
                   HorizontalAlignment="Stretch"
                   Grid.ColumnSpan="1"
                   Grid.Column="0"
                   Grid.Row="0"
                   Margin="0,0,0,0"
                   Grid.RowSpan="1">

            <StackPanel>
                <StackPanel.Background>
                    <LinearGradientBrush>
                        <GradientStop Color="White" Offset="0" />
                        <GradientStop Color="DarkKhaki" Offset=".3" />
                        <GradientStop Color="DarkKhaki" Offset=".7" />
                        <GradientStop Color="White" Offset="1" />
                    </LinearGradientBrush>
                </StackPanel.Background>
                <StackPanel Margin="10">
                    <Button Name="simpleButton"
                            Click="simpleButtonClick"
                            KeyDown="simpleButton_KeyDown">Simple</Button>
                    <Button Name="cubeButton"
                            Click="cubeButtonClick">Cube</Button>
                </StackPanel>
            </StackPanel>
            <Viewport3D Name="mainViewport"
                        ClipToBounds="True">
                <Viewport3D.Camera>
                    <PerspectiveCamera FarPlaneDistance="100"
                                       LookDirection="-11,-10,-9"
                                       UpDirection="0,1,0"
                                       NearPlaneDistance="1"
                                       Position="11,10,9"
                                       FieldOfView="70" />
                </Viewport3D.Camera>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <DirectionalLight Color="White" Direction="-2,-3,-1" />
                    </ModelVisual3D.Content>
                </ModelVisual3D>
            </Viewport3D>
        </DockPanel>
    </Grid>
</Window>

this is inide XAML.cs

private void simpleButton_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.P) {
        //something to move the simpleButton
    }
}

I want to move simpleButton when P is pressed from keyboard, but I can’t seem to find any method or way to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:09:19+00:00Added an answer on May 23, 2026 at 12:09 pm

    if animation is not required just do

    if (e.Key == Key.P)
    {
       cubeButton.Margin = new Thickness(60, 50, 50, 60);
    }
    

    left,top,right,bottom should be numbers

    and you have added keydown event to button so button must be focused in order to receive the keydown event

    also look at TranslateTransform in WPF

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my XAML code: <Window x:Class=CarFinder.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Search for cars in TuMomo Height=480
I have below XAML code : <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml DataContext={Binding RelativeSource={RelativeSource Self}} WindowStartupLocation=CenterScreen
My XAML code is like this: <Window xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation' xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml' Title ='Print Preview
The following xaml code works: <Window x:Class=DerivedTemplateBug.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:DerivedTemplateBug Title=Window1 Height=300 Width=300> <Button>
My xaml code is below; <Page x:Class=Ab3d.PowerToys.Samples.Objects3D.Model3DFactorySample xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:cameras=clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys xmlns:ab3d=clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys xmlns:visuals=clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys Title=AllModelsSample MinWidth=600>
I have the below code-behind: public partial class MainWindow : Window { public MainWindow()
Here is a window with a simple list: The code is straight-forward: <Window x:Class=Wpf_List.MainWindow
What we ideally need is, to know how Microsoft handles XAML generated code (Those
Below you can see my .xaml.cs code. The app opens fine. There are 4
Bellow is the code behind and the Xaml for a demo app to review

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.