Hi all,

Here is my Problem, I have created a Simple TestBed Application with a UserControl and Embedded it in MainWindow.

I have a class which contains default values for the visible cone shape. On the window i also have 3 sliders which between them and a sub create a 24 bit hexadecimal colour reference.

The value of this is placed in a textbox to confirm it is actually changing. However the cone's colour is not updated to reflect this change.

Here is the code

MainWindow Code:
  1. Imports _3d_UI.Numbers
  2. Class MainWindow
  3.     Private Sub UpdateColour()
  4.         ' get the values of the slider and convert into a format that Colour will accept
  5.        If SliderG Is Nothing Or SliderB Is Nothing Then Return
  6.         Colour = "#" + CInt(SliderR.Value).ToString("X2")
  7.         Colour = Colour + CInt(SliderG.Value).ToString("X2")
  8.         Colour = Colour + CInt(SliderB.Value).ToString("X2")
  9.         'TODO update component
  10.  
  11.         TextBox1.Text = Colour
  12.     End Sub
  13.  
  14.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
  15.  
  16.     End Sub
  17.  
  18.     Private Sub SliderR_ValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Double)) Handles SliderR.ValueChanged
  19.         UpdateColour()
  20.     End Sub
  21.  
  22.     Private Sub SliderG_ValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Double)) Handles SliderG.ValueChanged
  23.         UpdateColour()
  24.     End Sub
  25.  
  26.     Private Sub SliderB_ValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Double)) Handles SliderB.ValueChanged
  27.         UpdateColour()
  28.     End Sub
  29.  
  30.  
  31.     Public Sub New()
  32.  
  33.         ' This call is required by the designer.
  34.         InitializeComponent()
  35.  
  36.         ' Add any initialization after the InitializeComponent() call.
  37.         'UpdateColour()
  38.     End Sub
Code:
{MainWindow.xaml}

<Window
      x:Class="MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:_3d_UI"
      x:Name="Window"
      Title="3d ui test"
      Width="746" Height="419" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <Window.Resources></Window.Resources>
    <Grid x:Name="LayoutRoot">
        <local:Viewer3D Margin="0,0,102,0" />
        <Slider Height="255" HorizontalAlignment="Left" Margin="628,113,0,0" Name="SliderR" VerticalAlignment="Top" Width="28" Orientation="Vertical" Maximum="255" Value="255" SmallChange="1" LargeChange="16" />
        <Slider Height="255" HorizontalAlignment="Left" Margin="662,113,0,0" Name="SliderG" Orientation="Vertical" VerticalAlignment="Top" Width="28" Maximum="255" Value="128" LargeChange="16" SmallChange="1" />
        <Slider Height="255" HorizontalAlignment="Left" Margin="696,113,0,0" Name="SliderB" Orientation="Vertical" VerticalAlignment="Top" Width="28" Maximum="255" Value="0" LargeChange="16" SmallChange="1" />
        <Label Content="R" Height="28" HorizontalAlignment="Left" Margin="628,79,0,0" Name="Label1" VerticalAlignment="Top" />
        <Label Content="G" Height="28" HorizontalAlignment="Left" Margin="662,79,0,0" Name="Label2" VerticalAlignment="Top" />
        <Label Content="B" Height="28" HorizontalAlignment="Left" Margin="696,79,0,0" Name="Label3" VerticalAlignment="Top" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="628,12,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="632,53,0,0" Name="TextBox1" VerticalAlignment="Top" Width="81" Text="" />
    </Grid>
</Window>
Class Numbers Code:
  1. Public Class Numbers
  2.     Shared Property Colour As String = "#0000FF"
  3.     Shared Property Positions As String = "0.293893 -0.5 0.404509  0.475528 -0.5 ... ... 0.404509  0 0.5 0  0 0.5 0  "
  4.     Shared Property Normals As String = "0.7236065,0.4472139,0.5257313  0.2763934,0.4472138,0.8506507  ... ...  0.5308242,0.4294462,0.7306172  0.858892,0.429446,0.279071  "
  5.     Shared Property Indices As String = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 "
  6. End Class
(edited for Simplicity)

Code:
{Viewer3d.xaml}

<UserControl x:Class="Viewer3D"
             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" 
             xmlns:local="clr-namespace:_3d_UI"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.Resources>
            <local:Numbers x:Key="Colour" />
            <local:Numbers x:Key="Positions" />
            <local:Numbers x:Key="Normals" />
            <local:Numbers x:Key="Indices" />
        </Grid.Resources>
        <!-- Place a Label control at the top of the view. -->
        <Label 
				HorizontalAlignment="Center" 
				TextBlock.TextAlignment="Center" 
				FontSize="20" 
				Foreground="Red"
				Content="Model: Cone"/>
      <!-- Viewport3D is the rendering surface. -->
        <Viewport3D  DataContext="{Binding Source={StaticResource Indices}}" Name="myViewport" >
        <!-- Add a camera. -->
        <Viewport3D.Camera>
          <PerspectiveCamera 
						FarPlaneDistance="20" 
						LookDirection="0,0,1" 
						UpDirection="0,1,0" 
						NearPlaneDistance="1" 
						Position="0,0,-3" 
						FieldOfView="45" />
        </Viewport3D.Camera>
        <!-- Add models. -->
        <Viewport3D.Children>
          <ModelVisual3D>
            <ModelVisual3D.Content>
              <Model3DGroup >
                <Model3DGroup.Children>
                  <!-- Lights, MeshGeometry3D and DiffuseMaterial objects are added to the ModelVisual3D. -->
                  <DirectionalLight Color="#FFFFFFFF" Direction="3,-4,5" />
                  <!-- Define a red cone. -->
                  <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D 
    Positions="{Binding Path=Positions}" 
    Normals="{Binding Path=Normals}" 
    TriangleIndices="{Binding Path=Indices}">                                          
                                        </MeshGeometry3D>
                                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                      <DiffuseMaterial>
                        <DiffuseMaterial.Brush>
                          <SolidColorBrush x:Name="MySolidColorBrush"
                            Color="{Binding Path=Colour}"  
                            Opacity="1.0"/>
                        </DiffuseMaterial.Brush>
                          
                      </DiffuseMaterial>
                    </GeometryModel3D.Material>
                      
                  </GeometryModel3D>
                </Model3DGroup.Children>
                  
              </Model3DGroup>
            </ModelVisual3D.Content>
              
          </ModelVisual3D>
            
        </Viewport3D.Children>
            <Viewport3D.Triggers>
                <EventTrigger RoutedEvent="Viewport3D.MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                Storyboard.TargetName="MySolidColorBrush"
                Storyboard.TargetProperty="Color"
                From="Blue" To="Red" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>

                <EventTrigger RoutedEvent="Viewport3D.MouseLeave">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                Storyboard.TargetName="MySolidColorBrush"
                Storyboard.TargetProperty="Color"
                From="Red" To="blue" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>

            </Viewport3D.Triggers>
      </Viewport3D>
    </Grid>
</UserControl>
This to me is not very intuitive and i am probably doing this wrong, any pointers would be helpful...