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, MouseButton开发者_StackOverflow社区EventArgs 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;
}
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)
?
精彩评论