4

Wondering if there's any trick to accessing a nested control in the code-behind ?

given some XAML along the lines of

<UserControl>    
    <textbox />
    <DataGrid Name="MyGrid">
        <Columns>
            <Column field=ABC>
                <EditType>
                    <ComboBox Name="myCombo1"/>

I can access this.MyGrid but cannot access this.myCombo1 !!

0

2 Answers 2

2

Everytime that I have run into this I have be able to resolve it by using x:Name instead of Name. This may not be the issue in your case but give it a try.

Sign up to request clarification or add additional context in comments.

10 Comments

pretty strange, did not work for me ! I'm using vs2010 sp1, .net 4
@Kumar The example that you gave doesn't compile either I am missing some namespace or not knowing what control you are using for sure, can you give a more complete example that can be dropped into an UserControl and tested?
the sample uses devx wpf controls, i can upload more if you have those or are willing/able to install their trial versions
@Kumar Sorry I do not have those library's, am downloading trial now
@Kumar I have the controls now if you want please post a more complete example
|
0

In simple cases you can access elements using their name, but looks like combobox is datatemplate part, you can work with visual tree at runtime using VisualTreeHelper, but if you use mvvm & code right usually you don't need to access elements directly. Can you provide more information on general problem or test project to reproduce issue?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.