Click here to Skip to main content
15,919,336 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this is my code

C#
if (view.Margin == new Thickness(view.Margin.Top > 0, -1, 0, 0))
        {
          //code in here
        }


can some one please explain why this isn't working and please tell me another that i can do this?

I get these errors

VB
Error   2   Argument 1: cannot convert from 'bool' to 'double'  C:\Users\Kyle\documents\visual studio 2010\Projects\Project Hat\Project Hat\MainGame.xaml.cs    33  46  Project Hat


Error	1	The best overloaded method match for 'System.Windows.Thickness.Thickness(double, double, double, double)' has some invalid arguments	C:\Users\Kyle\documents\visual studio 2010\Projects\Project Hat\Project Hat\MainGame.xaml.cs	33	32	Project Hat
Posted

view.Margin.Top > 0 is a boolean.
The Thickness constructor accepts double only.
Passing a boolean doesn't make sense. What exactly are you trying to achieve?
 
Share this answer
 
v2
Comments
[no name] 16-Aug-11 5:54am    
Well, im dragging this control right and I want something to happen when it reaches a point greater then then x
Simon Bang Terkildsen 16-Aug-11 6:00am    
I mean what do you try to do when you write "view.Margin.Top > 0" as the first parameter to the constructor of Thickness?
[no name] 16-Aug-11 7:07am    
well I think [view.Margin.Top] is the current distant from the top and as you can see the [view.Margin.Top] changes allot and it must not go past a certain point so it should look something like 0 = 1 by using the > symbol, so 0 = x or [view.Margin.Top] so yeh i hope i helped
Simon Bang Terkildsen 16-Aug-11 7:18am    
Doesn't make sense to me at all. First of, the first parameter passed to the constructor is left not top (left, top, right, bottom).
Second, 0 = 1?
Sergey Alexandrovich Kryukov 17-Aug-11 1:58am    
Well, you answered, got my 5. I would like to warn you: don't hope to explain things to this very inquirer -- many tried hard. Sorry, systemerror121.
--SA
Try ternary operator
C#
new Thickness(view.Margin.Top>0?1:0, -1, 0, 0)
 
Share this answer
 
Comments
[no name] 16-Aug-11 5:56am    
I don't understand this code, please explain
Simon Bang Terkildsen 16-Aug-11 6:01am    
have a look at this MSDN entry ?: Operator (C# Reference)
Sergey Alexandrovich Kryukov 17-Aug-11 1:59am    
Reasonable guesswork, my 5. Now try to explain it :<.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900