views:

255

answers:

5

In Xaml page I reference my custom control this way:

<MyNamespace:CustControl x:Name="Cust1" />

Now I want change the property of this custom control in MouseLeftButtonDown event trigger:

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {

    }

But when I try to write something like

CustControl.IsSelected = true;

An error says: An object reference is required ..

I think it's all about "MyNamespace" namespace, but don't know how to reference it.

+2  A: 

The x:Name is "Cust1", so you would refer to it as Cust1:

Cust1.IsSelected = true;

I.e. Cust1 is the name of the instance; CustControl is the name of the type.

itowlson
+2  A: 

You should be referencing Cust1, but sometimes Visual Studio does not immediately create a field member for the control. Try typing Cust1.IsSelected and even if Visual Studio doesn't like it, try building to see if it succeeds.

Josh Einstein
+2  A: 

You would reference is as "Cust1", not its type.

Cust1.IsSelected = true;
Anderson Imes
+2  A: 

CustControl is the name of the class; Cust1 is the name of the instance.

Try Cust1.IsSelected = true.

SLaks
+2  A: 

try:

Cust1.IsSelected = true;

where "Cust1" is the Name property of the control

If WPF & asp.net work the same way "CustControl" is the name of the class, "Cust1" is the instance.

brian chandley