Skip to main content

Microsoft Silverlight

Answered Question Link to all shapeRSS Feed

(0)

omerf
omerf

Member

Member

2 points

9 Posts

Link to all shape

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
K2P2

Participant

Participant

1028 points

337 Posts

Re: Link to all shape

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"?

 

omerf
omerf

Member

Member

2 points

9 Posts

Re: Re: Link to all shape

 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;
        }


K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Re: Link to all shape

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 Tang - MSFT
Min-Hong...

Contributor

Contributor

3619 points

412 Posts

Re: Re: Link to all shape

Hi,

  You can just register all shapes' mouse enter and mouse leave event to these two handlers.

  It should work.

Best Regards

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

shamrat231
shamrat231

Contributor

Contributor

4717 points

595 Posts

Answered Question

Re: Re: Link to all shape

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 Mahmud
Software 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.

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities