|
I have a grid gr and divided it into 5 row, 5 column and placed a Image in it
Image tem = new Image();
tem.Source = new BitmapImage(new Uri("..."));
gr.Children.Add(tem);
tem.SetValue(Grid.ColumnProperty,0);
tem.SetValue(Grid.RowProperty,0);
tem.MouseLeftButtonDown += new MouseButtonEventHandler(tem_MouseLeftButtonDown);
tem.MouseLeftButtonUp+= new MouseButtonEventHandler(tem_MouseLeftButtonUp);
tem.MouseMove += new MouseButtonEventHandler(tem_MouseMove);
Now, i want to make tem_MouseLeftButtonDown, tem_MouseLeftButtonUp, tem_MouseMove to move Image from (row=i,column=j) to (row=Mouse point,column=Mouse point), in window form i can but in wpf i can't.
Sorry for my english.
Thank
|
|
|
|
|
The Grid control, being a Panel element, is suited for layout
of child elements. For what you are doing, it would be much simpler
to use another simpler panel like a Canvas and keep track of the
cell coordinates yourself.
That's just my opinion. You could do it with a Grid, but when I picture
the code in my head, it looks way messier than it would be using a canvas.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I was thinking that, too. I am assuming he wants the image to jump between cells, not move smoothly, but even then, it makes more sense to track positions than use an actual grid, IMO.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Agreed. I was thinking mostly of the hit-testing being messy,
but looking again, I see that WPF drag and drop could be used with
drop targets in each cell to let the framework do a lot of that.
That may even be simpler than using a canvas
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I am newbie to WPF development. We need to develop a kisok application, so is there any sample opensource kiosk project available to learn.
Is there any concept similar to Asp.net master page in WPF. It would be great if you guys can direct us to some similar sample application
|
|
|
|
|
What sort of application do you need to build ? What will it do ? Who is it for ? By kiosk, you just mean that it will fill the entire screen ? Will it work with a touch screen ? You've done ASP.NET then and you're just new to WPF ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: What sort of application do you need to build ?
This application is used in Hotels where customers can get informations
Christian Graus wrote: By kiosk, you just mean that it will fill the entire screen ?
Yes it's a full screen application. Which runs on kiosk machines
Christian Graus wrote: Will it work with a touch screen ?
Yes it should work on touch screen
Christian Graus wrote: ou've done ASP.NET then and you're just new to WPF
Yes I have worked with ASP.net. This project is going to be my first WPF work.
My queries are
1. Is there any Masterpage type concept in WPF.
I have gone through some sample application. There will be a main window and each content area is created as an user control. All user controls will be placed in main window and show/visible one at a time. I like the idea of creating it as a separate control. Is there any way to dynamically load when needed (Same as placing a panel in ASp.net). A animation affect which will make the transition looks better.
I would be great if you can share some of your ideas/Sample application familer. This project has a tight deadline and we don't have enough time to train ourself completely.
|
|
|
|
|
Whoah - you don't have enough time to train yourselves completely and you're coding to a tight deadline on a WPF application. You do know that WPF has a huge learning curve don't you? It's more a learning precipice than curve, and you can't just throw yourself at it and hope that something sticks.
You need to raise this with your project manager right now - you're undertaking a development in a new technology without adequate research and training, and you have a tight deadline. There is too much risk there, and she needs to start making some decisions right now otherwise you are not going to deliver the application or the application is going to be an unmaintainable mess - either way, the client has been hosed.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: you can't just throw yourself at it and hope that something sticks.
I did, and it f*ckin' hurts.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
That's the funniest answer I've read today.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Yes thats true. Project manager is not a good technical person and he is not aware of WPF concepts. He committed deadline thinking that there is nothing new in this technology. He will stick on this comments . So we have to do something from our side.
|
|
|
|
|
I agree - a project which is your first with WPF AND has a tight deadline, can only be a disaster. WPF changes so many things, I'd not recommend anyone do their first commercial project in it, unless they have a lot of time, or have done a lot of work at home first.
Having said that, a kiosk application seems like it's pretty simple. I am not sure, but I believe there was an early proof of concept of WPF which is freely available which was basically a kiosk application, it had a 3D rotating group of videos on it. That might be worth looking at. The touch screen stuff takes care of itself, just build a UI where all the buttons are big enough to touch.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: just build a UI where all the buttons are big enough to touch
I made my button as big as the screen.....it does nothing when I touch it.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
How can I call a MVC controller method in Silverlight en give the method some parameters.
The parameter wil be a IList.
Thanks,
|
|
|
|
|
|
Hi,
I am working on a silverlight application. In this I need to send mail from a .aspx page. But while sending mail I am getting the below exception
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."
Code I hve written is
string to = "test2@gmail.com";
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("test1@gmail.com", to,"Hi", "Test");
MyMailMessage.IsBodyHtml = true;
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("test1@gmail.com", "pswpsw");
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
If you have have any idea to solve this please reply me.
Thanks in advance.
|
|
|
|
|
Since this question has nothing to do with Silverlight, you may
get more response on perhaps the .NET Framework or ASP.NET board.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I' m building a sample in which I want to move an object. I'm not fully familiar with Blend and Xaml and the C# code behind, but I really don't understand why my cursor is far away from the object (is it canvas?... I don't know, in fact I'm shooting in the dark).
Here' s my xaml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CanvasMove.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas Height="80" HorizontalAlignment="Left" Margin="100,100,0,0" VerticalAlignment="Top" Width="80">
<Rectangle Fill="#FF80C1E4" Height="80" Width="80" RenderTransformOrigin="0.5,0.5" MouseLeftButtonUp="CanvasUp" MouseLeftButtonDown="CanvasDown"/>
<Rectangle Fill="#FF7AB7D8" Height="32" Width="32" Canvas.Left="24" Canvas.Top="24"/>
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0" x:Name="CanvasTransform"/>
</Canvas.RenderTransform>
</Canvas>
</Grid>
</UserControl>
Here's my C#:
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
CanvasTransform.X = e.GetPosition(null).X;
CanvasTransform.Y = e.GetPosition(null).Y;
}
|
|
|
|
|
TCPMem wrote: I really don't understand why my cursor is far away from the object
You are responding to all the MouseMove events for the UserControl.
When you call e.GetPosition(null) you are getting the cursor position
relative to the entire Silverlight plugin.
Your Canvas is 100 pixels down and to the right of the plugin. The
Rectangle you are moving is another 24 pixels down and to the right
of the Canvas.
So the cursor is always 124x124 away from the object.
What are you trying to do? Do you want to be able to drag the
rectangle with the mouse by clicking on it?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
"What are you trying to do? Do you want to be able to drag the
rectangle with the mouse by clicking on it?"
Yes. That's exactly what I want. How can I make it?
|
|
|
|
|
TCPMem wrote: That's exactly what I want. How can I make it?
First, I misread your code so I was wrong about how far off the cursor
was from the Canvas. I now see you're moving the entire canvas, not just
the rectangle, which is the way I read it
Anyway, here's a simple example that will hopefully get you going:
<Grid x:Name="LayoutRoot" Background="White">
<Canvas Height="80" HorizontalAlignment="Left" Margin="100,100,0,0" VerticalAlignment="Top" Width="80"
MouseLeftButtonUp="Canvas_MouseLeftButtonUp"
MouseMove="Canvas_MouseMove"
MouseLeftButtonDown="Canvas_MouseLeftButtonDown" >
<Rectangle Fill="#FF80C1E4" Height="80" Width="80" RenderTransformOrigin="0.5,0.5" />
<Rectangle Fill="#FF7AB7D8" Height="32" Width="32" Canvas.Left="24" Canvas.Top="24"/>
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0" x:Name="CanvasTransform"/>
</Canvas.RenderTransform>
</Canvas>
</Grid>
Point anchorPoint;
bool isInDrag = false;
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
anchorPoint = e.GetPosition(null);
element.CaptureMouse();
isInDrag = true;
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (isInDrag)
{
Point currentPoint = e.GetPosition(null);
CanvasTransform.X = CanvasTransform.X + currentPoint.X - anchorPoint.X;
CanvasTransform.Y = CanvasTransform.Y + currentPoint.Y - anchorPoint.Y;
anchorPoint = currentPoint;
}
}
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (isInDrag)
{
FrameworkElement element = sender as FrameworkElement;
element.ReleaseMouseCapture();
isInDrag = false;
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I used http://msdn.microsoft.com/en-us/library/cc189066(VS.95).aspx this code to move an object only and wondered how can I do this with the entire canvas. I took a look at your code and replaced
Rectangle item = sender as Rectangle;
with yours:
FrameworkElement element = sender as FrameworkElement;
and it happened. Thanks!
|
|
|
|
|
I need to determine whether the FlowDocument inside a RichTexBox fits without exceeding the height of the RichTextBox. If I could get an event that announces that the vertical scroll bar is visible when VerticalScrollBarVisibility="Auto" , that would do the trick, but I haven't been able to discover how to do that. Likewise a property giving me the computed height of the content would also do it, but I don't seem to be able to get that, either. Any other way? What I want to do is to be able to bring up a resizable window containing the content if the content exceeds the actual height and width of the RichTextBox.
|
|
|
|