Skip to main content
Home Forums General Silverlight Getting Started Link to all shape
5 replies. Latest Post by shamrat231 on November 11, 2009.
(0)
omerf
Member
2 points
9 Posts
11-06-2009 5:53 AM |
Hi,
İ have a world map and all country is shape i want make when the mouse on the shape shape visible is hidden.I can do it for 1 shapes but i want apply it to all shapes how can i add this event to all shapes?
Regads
K2P2
Participant
1028 points
337 Posts
11-06-2009 5:55 PM |
A few questions:
1) Where did you get the world map?2) When you say "shape" do you mean a png file, jpg?3) How did you do it for the "1 shape"?
11-06-2009 6:21 PM |
its ai file. each country is shape from adobe illustrator.
İ use this code for one shape.How can i apply this to all shapes in page.private void Path_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { Shape img = ((Shape)sender); img.Opacity = 0; } private void Path_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { Shape img = ((Shape)sender); img.Opacity = 100; }
11-06-2009 7:41 PM |
I'm not familiar with the Shape class - it doesn't sound like the System.Windows.Shapes.Shape class.
Anyway, can't you do the following for all of them? shape.MouseEnter += new WhateverEventHandler ( Path_MouseEnter );
In this case they would all go to the same event handler and you're done.
Or, if not, can you put all of your Shapes in an array or List when you load them?
Then in your handler you can do something like this:
Shape img = (Shape) sender;
img = FindShapeInList( img );// But I think this is unnecessary since the first solution should send in the correct Shape.
img.Opacity = whatever.
Min-Hong...
Contributor
3584 points
411 Posts
11-11-2009 4:37 AM |
You can just register all shapes' mouse enter and mouse leave event to these two handlers.
It should work.
Best Regards
shamrat231
4717 points
595 Posts
11-11-2009 4:56 AM |
omerf:İ use this code for one shape.How can i apply this to all shapes in page
Your code is perfect for this scenario. You can assign the handler to all shapes as shown below to your present MouseEnter an MouseLeave handler.
<UserControl x:Class="SilverlightApplication1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" Background="Bisque"> <Grid x:Name="LayoutRoot" Background="Black" Width="200" Height="100"> <Path x:Name="Path" MouseEnter="Path_MouseEnter" MouseLeave="Path_MouseLeave" /> <Path x:Name="Path1" MouseEnter="Path_MouseEnter" MouseLeave="Path_MouseLeave" /> <Path x:Name="Path2" MouseEnter="Path_MouseEnter" MouseLeave="Path_MouseLeave" /> <Path x:Name="Path3" MouseEnter="Path_MouseEnter" MouseLeave="Path_MouseLeave" /> </Grid></UserControl>
Please 'Mark as Answer' if it helps you
Sharker Khaleed MahmudSoftware Developer(MCP,MCTS,MCPD[web])
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.