Animating rectangle: Extension method must be defined in a non-generic static class
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
So far this is what I've got:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(this Image target, double newX, double newY)
{
var top = Canvas.GetTop(target);
var left = Canvas.GetLeft(target);
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);
trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}
}
It has an error code of
Extension method must be defined in a non-generic static class
The premise is just to move a rectangle using an animation/timer, however using WPFs make it harder to do so, any help, or even better ways of doing so, would be helpful!
c# wpf visual-studio-2012
add a comment |
So far this is what I've got:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(this Image target, double newX, double newY)
{
var top = Canvas.GetTop(target);
var left = Canvas.GetLeft(target);
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);
trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}
}
It has an error code of
Extension method must be defined in a non-generic static class
The premise is just to move a rectangle using an animation/timer, however using WPFs make it harder to do so, any help, or even better ways of doing so, would be helpful!
c# wpf visual-studio-2012
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replacethis Image target
byImage target
, which turns it into a reguar static method instead of an extension method.
– Clemens
Nov 23 '18 at 12:24
Even better:UIElement target
. Now you can use the method not only for Image elements.
– Clemens
Nov 23 '18 at 12:32
add a comment |
So far this is what I've got:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(this Image target, double newX, double newY)
{
var top = Canvas.GetTop(target);
var left = Canvas.GetLeft(target);
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);
trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}
}
It has an error code of
Extension method must be defined in a non-generic static class
The premise is just to move a rectangle using an animation/timer, however using WPFs make it harder to do so, any help, or even better ways of doing so, would be helpful!
c# wpf visual-studio-2012
So far this is what I've got:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(this Image target, double newX, double newY)
{
var top = Canvas.GetTop(target);
var left = Canvas.GetLeft(target);
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);
trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}
}
It has an error code of
Extension method must be defined in a non-generic static class
The premise is just to move a rectangle using an animation/timer, however using WPFs make it harder to do so, any help, or even better ways of doing so, would be helpful!
c# wpf visual-studio-2012
c# wpf visual-studio-2012
edited Nov 23 '18 at 12:20
FrankerZ
17.9k73067
17.9k73067
asked Nov 23 '18 at 12:18
SamoopSamoop
163
163
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replacethis Image target
byImage target
, which turns it into a reguar static method instead of an extension method.
– Clemens
Nov 23 '18 at 12:24
Even better:UIElement target
. Now you can use the method not only for Image elements.
– Clemens
Nov 23 '18 at 12:32
add a comment |
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replacethis Image target
byImage target
, which turns it into a reguar static method instead of an extension method.
– Clemens
Nov 23 '18 at 12:24
Even better:UIElement target
. Now you can use the method not only for Image elements.
– Clemens
Nov 23 '18 at 12:32
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replace
this Image target
by Image target
, which turns it into a reguar static method instead of an extension method.– Clemens
Nov 23 '18 at 12:24
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replace
this Image target
by Image target
, which turns it into a reguar static method instead of an extension method.– Clemens
Nov 23 '18 at 12:24
Even better:
UIElement target
. Now you can use the method not only for Image elements.– Clemens
Nov 23 '18 at 12:32
Even better:
UIElement target
. Now you can use the method not only for Image elements.– Clemens
Nov 23 '18 at 12:32
add a comment |
1 Answer
1
active
oldest
votes
Since you are expecting this Image
as the parameter in MoveTo
, it is considering this method as an extension method. More info here. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(UIElement target, double newX, double newY)
{
//Your code
}
}
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446592%2fanimating-rectangle-extension-method-must-be-defined-in-a-non-generic-static-cl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you are expecting this Image
as the parameter in MoveTo
, it is considering this method as an extension method. More info here. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(UIElement target, double newX, double newY)
{
//Your code
}
}
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
add a comment |
Since you are expecting this Image
as the parameter in MoveTo
, it is considering this method as an extension method. More info here. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(UIElement target, double newX, double newY)
{
//Your code
}
}
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
add a comment |
Since you are expecting this Image
as the parameter in MoveTo
, it is considering this method as an extension method. More info here. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(UIElement target, double newX, double newY)
{
//Your code
}
}
Since you are expecting this Image
as the parameter in MoveTo
, it is considering this method as an extension method. More info here. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TestMouseDown(object sender, MouseButtonEventArgs e)
{
MoveTo(imageTest, 100, 100);
}
public static void MoveTo(UIElement target, double newX, double newY)
{
//Your code
}
}
edited Nov 23 '18 at 12:38
Clemens
90.2k894186
90.2k894186
answered Nov 23 '18 at 12:31
shruti singhshruti singh
628
628
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
add a comment |
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
Thank you everyone! I appreciate the advice, although it may seem "obvious" and "easy" I'm still learning C#, and have been learning it for the past month, I'm new to the programming scene and I am still getting to grips with its basic concepts
– Samoop
Nov 23 '18 at 14:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446592%2fanimating-rectangle-extension-method-must-be-defined-in-a-non-generic-static-cl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why didn't just make this method "normal" static instead extension?(or just follow any other answer for this problem) however using WPFs make it harder how WPF can make something harder?
– Selvin
Nov 23 '18 at 12:23
The error message can't be more clear. You have to declare the MoveTo method in another class. Or simply replace
this Image target
byImage target
, which turns it into a reguar static method instead of an extension method.– Clemens
Nov 23 '18 at 12:24
Even better:
UIElement target
. Now you can use the method not only for Image elements.– Clemens
Nov 23 '18 at 12:32