c# - Add Image in a stackpanel based on textbox input -
I am trying to store the image in a stapple panel .. \ resources \ ebi.png Most of the time, the textbox input Based on "Atracount", the same image will be displayed in the StackPanel below, the sample code has been attempted, but it is getting an error saying
"The specified view is already visible to any other view Has a child or is the origin of a composition goal "
is the code below The Oshis:
private bitmap image bmp = new Bitmap image (new Uri ( "WpfApplication1; components / resources / ebi.png", Urikind. Riletiv Orsolut)); Private Zero EtReqCount_TextChanged (Object Sender, TextChangedEventArgs E) {StackPanel dynamicStackPanel = new StackPanel (); DynamicStackPanel.Width = 300; DynamicStackPanel.Height = 200; DynamicStackPanel.Background = New SolidColorBrush (Color. LightBu); DynamicStackPanel.Orientation = Orientation. Vertical; If (Attarcount.Text! = "") {For (int k = 1; k & lt; = int32.Parse (etReqCount.Text); k ++) {Image img = New system. Indova. Control Image (); // This difference makes Img.Source = bmp; DynamicStackPanel.Children.Add (img); }}}
XAML Code:
It is clear that the same image is already a child of the stackpennell, you can not add it repeatedly.
In addition, to save resources, you should use a private member to capture duplicated BMP:
Class outside the class, and inside the class :
Private bitmap image BMP = new bitmap image (new URI ("/ .... ebi.png", URIKAND.Relative and Ossolute); < P> You can create new instances of image:
for(int i = 0; i
Comments
Post a Comment