I would like to instantiate a class defined in C# in XAML and use it in both XAML and code. I found out that I can instantiate the object as a resource and use TryFindResource("...") to locate it in code but I am confused about how I should reference it later in XAML. Fore example, I have the following XAML code:
<UserControl.Resources>
<localx:PipeViewModel x:Key="pipeview" />
</UserControl.Resources>
<DockPanel Grid.Row="0" Grid.RowSpan="3" Grid.ColumnSpan="3" Grid.Column="0" Background="White">
<hx:HelixViewport3D x:Name="HelixViewport3D"
ZoomExtentsWhenLoaded="True"
CameraRotationMode="Trackball"
CameraMode="FixedPosition"
PanGesture="LeftClick">
<hx:DefaultLights />
<hx:DefaultLights />
<localx:PipeViewModel x:Name="pipeview" MyPipeModel="{Binding Path=PipeModel, RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=1}}"/>
</hx:HelixViewport3D>
</DockPanel>
I am not sure if the object instantiated in the resource section is the same one inserted in HelixVievPort3D. I suspect that using the same names doe not necessarily imply they are the same. How can I correctly insert the pipeview object in HelixViewPort?