Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a inkcanvas control by creating a custom inkcanvas class .I had taken the instances of this class and add them to stack panel.I dragged the one button control to the mainwindow.In the button click event the instance of stackpanel names (mycanvas1 ) was not visible.how to solve it.

here my code
C#



C#
public partial class MainWindow : Window
   {
       public MainWindow()
       {
           InitializeComponent();
           mycan mycanvas1 = new mycan();
           stkm.Children.Add(mycanvas1);
        }
       

private  void   savebtn_Click(object sender, RoutedEventArgs e )
 {
 
var files = Directory.GetFiles(@"C:\\Users\\SriRampavankumar\\Desktop\\proj").Length;
string fileName = namebox.Text.Substring(0, 3) + -+ ++files + ".txt";
string path2 = System.IO.Path.GetFullPath("C:\\Users\\tom\\Desktop\\proj");
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string var = System.IO.Path.Combine(docPath, path2);
string var1 = System.IO.Path.Combine(var, fileName);
            using (StreamWriter writer = new StreamWriter(var1))
            {
                string var6 = namebox.Text;
                string var7 = "                 ";
                string var8 = agebox.Text;

           }
Posted

1 solution

Hi Pavan

You can find child from StackPanel with this function which is given here
http://msdn.microsoft.com/en-us/library/system.windows.frameworktemplate.findname%28v=vs.110%29.aspx[^]

C#
private childItem FindVisualChild<childitem>(DependencyObject obj)
    where childItem : DependencyObject
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
        if (child != null && child is childItem)
            return (childItem)child;
        else
        {
            childItem childOfChild = FindVisualChild<childitem>(child);
            if (childOfChild != null)
                return childOfChild;
        }
    }
    return null;
}


and call following code on your button click -

C#
object obj = FindVisualChild<mycan>(stkm);


If you will add more than one child items into the stakpanel then give "Name" to each child item and check inside "FindVisualChild" function with "Name" property.
 
Share this answer
 
v2
Comments
pavan kadambari 5-Dec-14 5:00am    
Thank you ,I have created instance of inkcanvas like this
mycan mycanvas1 = new mycan();
mycan mycanvas2 = new mycan();that mycanvas1 has some properties like strokes
I want to use that mycanvas1.strokes property in the button click event.It was not possibe.
Punamchand Dhuppad 5-Dec-14 5:54am    
Did you get mycanvas1 object value in "obj" object ?
pavan kadambari 5-Dec-14 6:09am    
my namespace is getstrokes
Im trying to print the obj using
writer.writeline(obj);
I am getting getstrokes.mycan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900