Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I'm trying to write a WPF user control (output is a DLL) which is an assemblage of other WPF controls.
I added to the project the controls I need and I want to expose some of their properties in my user control, but I noticed that I cannot call them!
VB
Imports System.Windows.Media
Imports System.Windows.Media.Media3D
Imports HelixToolkit.Wpf
Imports System.Windows.Media.Drawing

Public Class viewer

    Public Property BackColor As Color
        Get
            Return Canvas1.Background ' <- this does not work, Canvas1 not accessible!
        End Get
        Set(ByVal color As Color)
            Canvas1.removed=color ' <- this does not work, Canvas1 not accessible!
        End Set
    End Property

End Class

Please help! I cannot inderstand what to do and I didn't find any example!

Thanks,
Giovanni
Posted

Is viewer the code behind for your user control/window? If it's not, then you can't set a property on a control like this because it's not actually part of that view.

[Edit]Amended to show the call to InitializeComponent()
VB
Imports System.Windows.Media
Imports System.Windows.Media.Media3D
Imports HelixToolkit.Wpf
Imports System.Windows.Media.Drawing

Public Class viewer
	Public Sub New()
		InitializeComponent()
	End Sub

	Public Property BackColor() As Color
		Get
			Return Canvas1.Background
		End Get
		Set
			Canvas1.removed = value
		End Set
	End Property

End Class
 
Share this answer
 
v2
Comments
rinaldin 6-Feb-14 9:57am    
Yes, it is the code behind my control.
If it helps, this is the XAML code:

<usercontrol x:class="UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300" xmlns:h="http://helixtoolkit.codeplex.com">
<grid>
<h:helixviewport3d height="300" horizontalalignment="Left" name="HelixViewport3D1" verticalalignment="Top" width="300" removed="Black" camerainertiafactor="0" infoforeground="White" isinertiaenabled="False" ismanipulationenabled="True" orthographic="True" showcoordinatesystem="True" showviewcube="False">
<Canvas Height="300" HorizontalAlignment="Left" Name="Canvas1" VerticalAlignment="Top" Width="300" ClipToBounds="True" />

Pete O'Hanlon 6-Feb-14 10:02am    
I don't see anywhere in your code that you call InitializeComponent. You need to call this in your constructor before you can get access to the controls on the UserControl.
rinaldin 6-Feb-14 10:05am    
ok thanks, but where to insert the call in the code behind? I cannot undestand where and how.
Pete O'Hanlon 6-Feb-14 10:25am    
I have amended my answer to show you how to call InitializeComponent.
rinaldin 6-Feb-14 10:29am    
Yes, but I cannot figure out how. I added:

Public Sub New()
Me.InitializeComponent() ' <- this is not a component of the class viewer
End Sub

and it does not work.
Solved! the first row of the XAML code must report the name of the class:

<usercontrol x:class="viewer" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" xmlns:h="http://helixtoolkit.codeplex.com">
<grid>
...




and then all the controls will be accessible!
 
Share this answer
 

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