tags:

views:

433

answers:

2

Hello

I created a UserControl in WPF:

In Xaml:

<UserControl x:Class="OutlookPanel.MailRelation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300"
    xmlns:graph="clr-namespace:MyPanel"
>
 <DockPanel>
<graph:Graph Name="theGraph" NodesBindingPath="ChildNodes"
               NodeTemplateSelector="{StaticResource nodeTemplateSelector}">
..
 </DockPanel>
</UserControl>

I cs:

object theThing = e.Parameter;
                    ((MailRelation)sender).theGraph.CenterObject = theThing;

This last sentence does not work as theGraph is not accessible. Any idea why i can access theGraph ?

Thanks

John

A: 

Probably because that property is private. Provide a public getter and you should be able to get it. In your code, add something like

 public Graph TheGraph  { get { return theGraph; } }
Erich Mirabal
Hi,No it does not work :public partial class MailRelation : UserControl { public Graph TheGraph { get { return theGraph; } } static MailRelation() {}the Graph is also not seen...John
Usually, that has been my problem. Did you change the other line of code to use TheGraph instead of theGraph?
Erich Mirabal
A: 

Name="theGraph"

should be

x:Name="theGraph"

from http://msdn.microsoft.com/en-us/library/ms752059.aspx

x:Name: Specifies a run-time object name for the instance that exists in run-time code after an object element is processed. You use x:Name for cases of naming elements where the equivalent WPF framework-level Name property is not supported. This happens in certain animation scenarios.

Jon Masters
Wow, it is true... Can you explain the difference?
Depends on what Graph is. What class does it extend?
Kent Boogaart
if the object you are working with does not contain a Name field already then you can use x:Name, which i believe is an extended property.
Jon Masters