tags:

views:

35

answers:

1
+1  Q: 

Creating controls

I am designing a silverlight application in which i have a image control in the left top corner and when i click the button and drag it to the form i should get duplicate of that control and dragged into my form.

Please help me with the code

I am trying to create the control dynamically in mouseleftbuttondown event but the controls are not being created.

Xaml

<UserControl xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  x:Class="Workflow.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:DesignWidth="640" d:DesignHeight="480">
    <Canvas x:Name="layout" Width="800" Height="600" Background="AliceBlue">
        <Image x:Name="MyImage" Source="21.jpg" Canvas.Left="10" Canvas.Top="10" Stretch="Uniform" 
             MouseLeftButtonDown="MyImage_MouseLeftButtonDown" ></Image>
    </Canvas>

</UserControl>

Code

private void MyImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            b = cs.LoadControl();
            layout.Children.Add(b);
        }

List<Ellipse> block = new List<Ellipse>();
        public Ellipse LoadControl()
        {
            Ellipse btn = new Ellipse();
            block.Add(btn);
            btn.Height = 50; btn.Width = 100;
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();
            mySolidColorBrush.Color = Color.FromArgb(0, 255, 255, 0);
            btn.Fill = mySolidColorBrush;
            Canvas.SetTop(btn, 50);
            Canvas.SetLeft(btn, 50);
            return btn;
        }
A: 

You are using Color.FromArgb(0, 255, 255, 0) which has 0 for alpha, which makes your control transparent. What if you try Color.FromArgb(255, 255, 255, 0)?

Gabe
oh yeah i got it thank you Gabe
Sathish
@Sathish: If this answers your quesion you should click the big tick that you see on the left to show that it is the accepted answer. Ordinarily you would also upvote it, afterall if the answer wasn't good you wouldn't accept it.
AnthonyWJones