I have a XAML file of some view where a complex 3D model is defined. The problem is that the part defining the model is quite big, it has over 0.5 MB and it's really hard to browse through the file. Is there a way I can move e.g the Model3DGroup into another file and then include it in my main XAML file? I use a SketchUp to XAML converter which creates files with <Model3DGroup xmlns="..." xmlns:x="..."> as their roots, so I'm almost sure it can be done in a convenient way.
My current XAML file looks like this:
<UserControl x:Class="BigAtom.Views.WorkspaceView"
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:TestProj"
mc:Ignorable="d"
d:DesignHeight="278" d:DesignWidth="274">
<Grid x:Name="RootVisual" Background="Beige" ClipToBounds="True">
<Canvas Name="DrawingCanvas" Grid.Row="0" Grid.Column="0" Width="0" Height="0" RenderTransform="1,0,0,-1,0,0" Margin="10">
<Viewport3D Name="Object3D" Width="50" Height="50" Margin="-25,-25" ClipToBounds="False">
<Viewport3D.Camera>
<OrthographicCamera x:Name="CamMain" Position="0 60 100" LookDirection="0 -60 -100"></OrthographicCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight x:Name="DirLightMain" Direction="-1,-1,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="MyModel">
<ModelVisual3D.Content>
<Model3DGroup>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-5.6166 10.4050 153.1136 [very long line]" TextureCoordinates="-5.616612 -10.405044 -3.582495 [very long line]" TriangleIndices="164 17 57 [very long line]"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Color="White" Brush="#ffffff"/>
</GeometryModel3D.Material>
<GeometryModel3D.BackMaterial>
<DiffuseMaterial Color="White" Brush="White"/>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Canvas>
</Grid>
</UserControl>
and I want to achieve something like this:
<UserControl x:Class="BigAtom.Views.WorkspaceView"
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:TestProj"
mc:Ignorable="d"
d:DesignHeight="278" d:DesignWidth="274">
<Grid x:Name="RootVisual" Background="Beige" ClipToBounds="True">
<Canvas Name="DrawingCanvas" Grid.Row="0" Grid.Column="0" Width="0" Height="0" RenderTransform="1,0,0,-1,0,0" Margin="10">
<Viewport3D Name="Object3D" Width="50" Height="50" Margin="-25,-25" ClipToBounds="False">
<Viewport3D.Camera>
<OrthographicCamera x:Name="CamMain" Position="0 60 100" LookDirection="0 -60 -100"></OrthographicCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight x:Name="DirLightMain" Direction="-1,-1,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="MyModel">
<ModelVisual3D.Content>
<Model3DGroup --- some kind of reference to the file which keeps the 3D model --- />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Canvas>
</Grid>
</UserControl>
#edit
McGarnagle's answer is generally OK, but in my case I also have some DataTemplate defined in my UserControl.Resources. Because of this, I had to create such a structure:
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type local:SomeType}" x:Key="SomeTypeTemplate">
....
</DataTemplate>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Models.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
I imagine you should be able to use a resource dictionary for this. Add a file, say, "Models.xaml" with the definitions:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Model3DGroup x:Key="TheModelContent">
...
</Model3DGroup>
</ResourceDictionary>
Then reference the file in your UserControl, and refer to the models using the StaticResource keyword:
<UserControl>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Models.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- other resources here -->
</ResourceDictionary>
</UserControl.Resources>
...
<ModelVisual3D Content="{StaticResource TheModelContent}">
...
</UserControl>
Related
We use vector icons exported from Expression Design in our application, but I just noticed that all empty space in the icons gets trimmed away when they are displayed inside a stretched Image. Since the whole point of having vector icons is to allow them to stretch and scale nicely, this seems very strange.
Here is an example. Both the red and the blue star are designed in a 32 pixels wide document, but the blue star is much smaller. Setting the stretch property to Uniform suddenly makes the two icons the same size.
Is it possible to solve this and keep the whitespace around the icons? I guess a possible workaround would be to add a transparent background rectangle that covers the whole icon area, but this seems like a bad solution to me.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="GeneralTest.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<DrawingImage x:Key="small_blue_star">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="Blue" Geometry="F1 M 20.4989,22C 20.4634,22.0177 16.2771,19.0022 16.2416,19.0022C 16.2061,19.0022 12.0021,22.0177 11.9844,22C 11.9489,21.9823 13.4921,17.0332 13.4744,16.9977C 13.4744,16.9623 9.4655,14.0354 9.48323,13.9999C 9.48323,13.9644 14.45,14.0177 14.4855,13.9999C 14.5032,13.9822 16.2061,8.99765 16.2416,8.99765C 16.2771,8.99765 17.9623,13.9822 17.98,13.9999C 18.0155,14.0177 22.9823,13.9644 23,13.9999C 23,14.0354 18.9911,16.9623 18.9911,16.9977C 18.9734,17.0332 20.5166,21.9823 20.4989,22 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="big_red_star">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="Red" Geometry="F1 M 26.0781,32C 25.9941,32.0436 16.0823,24.6277 15.9983,24.6277C 15.9143,24.6277 5.96055,32.0436 5.91855,32C 5.83455,31.9564 9.48848,19.7856 9.44648,19.6983C 9.44648,19.6111 -0.0453207,12.4133 -0.00332647,12.326C -0.00332647,12.2388 11.7564,12.3697 11.8404,12.326C 11.8824,12.2824 15.9143,0.0243702 15.9983,0.0243702C 16.0823,0.0243702 20.0723,12.2824 20.1142,12.326C 20.1982,12.3697 31.958,12.2388 32,12.326C 32,12.4133 22.5082,19.6111 22.5082,19.6983C 22.4662,19.7856 26.1201,31.9564 26.0781,32 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Window.Resources>
<StackPanel x:Name="LayoutRoot">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Stretch=None" Width="100"/>
<Image Source="{StaticResource big_red_star}" Width="32" Stretch="None"/>
<Image Source="{StaticResource small_blue_star}" Width="32" Stretch="None"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Stretch=Uniform" Width="100"/>
<Image Source="{StaticResource big_red_star}" Width="32" Stretch="Uniform" />
<Image Source="{StaticResource small_blue_star}" Width="32" Stretch="Uniform"/>
</StackPanel>
</StackPanel>
</Window>
I am using Microsoft's Ribbon of WPF 4.5 and developing application using VS2012 (C#) on Win 8 machine. I want to make my application show RibbonApplicationMenu like the "File"-menu of Office Word 2010, but I can't find out which control is used for it (see attached screenshot, red-marked control number 1 and 2). I also tried RibbonApplicationSplitMenuItem but it is more like Office old-style.
Maybe anyone can tell me. Thank you in advance.
1) I suggest you use the ribbon that's inside .net 4.5 (add a reference to System.Windows.Controls.Ribbon). I'm not sure what you used the external one.
2)What you need for a menu is Ribbon.ApplicationMenu
3) Below is a working ribbon (based on that) that includes several types of buttons as well as a menu that you require.
All you need for this to work is to add an images folder with an "options.png" in it.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ribbon SelectedIndex="0" Grid.Column="0" Grid.ColumnSpan="5">
<!-- Help Pane, located at the right-hand side -->
<Ribbon.HelpPaneContent>
<RibbonButton SmallImageSource="Images\options.png" />
</Ribbon.HelpPaneContent>
<!-- Quick Access Toolbar - located at the upper-left corner -->
<Ribbon.QuickAccessToolBar>
<RibbonQuickAccessToolBar>
<RibbonButton x:Name ="Save" SmallImageSource="Images\options.png" />
<RibbonSplitButton x:Name ="Undo" SmallImageSource="Images\options.png" >
<RibbonSplitMenuItem Header="Undo 1" />
<RibbonSplitMenuItem Header="Undo 2" />
</RibbonSplitButton>
<RibbonSplitButton x:Name="Redo" SmallImageSource="Images\options.png" >
<RibbonSplitMenuItem Header="Redo 1" />
<RibbonSplitMenuItem Header="Redo 2" />
</RibbonSplitButton>
<RibbonCheckBox Label="Sound" KeyTip="X" />
</RibbonQuickAccessToolBar>
</Ribbon.QuickAccessToolBar>
<!-- Application Menu, located at the left-hand side (down arrow) -->
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu KeyTip="F">
<RibbonApplicationMenuItem Header="Options1" ImageSource="Images\options.png" />
<RibbonApplicationMenuItem Header="Exit2" ImageSource="Images\options.png" />
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<!-- Ribbon Tab #1: Home -->
<RibbonTab Header="Home" KeyTip="H" >
<!-- Home group-->
<RibbonGroup x:Name="ClipboardGroup" Header="Home">
<RibbonMenuButton LargeImageSource="Images\options.png" Label="Activate" KeyTip="V">
<RibbonToggleButton SmallImageSource="Images\options.png" Label="blabla" KeyTip="H" />
<RibbonToggleButton SmallImageSource="Images\options.png" Label="option2" />
</RibbonMenuButton>
<RibbonToggleButton SmallImageSource="Images\options.png" Label="Toggle " KeyTip="X" />
<RibbonToggleButton x:Name="Toggle11" SmallImageSource="Images\options.png" Label="Just a Toggle" KeyTip="FP" />
</RibbonGroup>
<!-- Employee And Payroll group-->
<RibbonGroup x:Name="Employee" Header="Adjust View">
<RibbonMenuButton LargeImageSource="Images\options.png" Label="Test" KeyTip="V">
<RibbonMenuItem ImageSource="Images\options.png" Header="Keep Text Only" KeyTip="T"/>
<RibbonMenuItem ImageSource="Images\options.png" Header="Paste Special..." KeyTip="S"/>
</RibbonMenuButton>
<RibbonCheckBox SmallImageSource="Images\options.png" Label="Sound" KeyTip="X" />
</RibbonGroup>
</RibbonTab>
<!-- Ribbon Tab #2: Launch -->
<RibbonTab Header="Settings" KeyTip="I">
<!-- Launch/Applications group-->
<RibbonGroup Header="Settings">
<RibbonButton SmallImageSource="Images\options.png" Label="Record" KeyTip="C" />
</RibbonGroup>
</RibbonTab>
<RibbonTab Header="PageLayout" KeyTip="L">
<!-- Launch/Applications group-->
</RibbonTab>
</Ribbon>
</Grid>
</Window>
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu>
<RibbonApplicationMenu.AuxiliaryPaneContent>
<Label Content="Right panel!"></Label>
</RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonApplicationMenuItem Header="Exit" Click="ShutDown" />
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
haha
Finally I found the answer in wpf sample browser of infragistics netadvantage. The no. 1 is called "backstage" (ribbon 2010 style), no. 2 is a "application menu item".
(in my opinion) The infragistics' ribbon is easier to use than the Microsoft's one, since I can't find tutorial how to create backstage (ribbon 2010 style); the existing tutorials are mostly using old ribbon (2007 style).
Here take a look my simple code snippet:
<Window x:Class="TestRibbon.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:igRibbon="http://infragistics.com/Ribbon"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
Height="768"
Width="1024"
Title="Test Ribbon"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Grid x:Name="gridMain">
<igRibbon:XamRibbon x:Name="ribbonMain"
Width="Auto"
ApplicationMenuMode="Office2010"
ApplicationAccentColor="Blue">
<igRibbon:XamRibbon.ApplicationMenu2010>
<igRibbon:ApplicationMenu2010 Caption="File">
<igRibbon:ApplicationMenu2010Item KeyTip="I"
Header="Information">
<igRibbon:ApplicationMenu2010Item.Content>
<Grid Margin="20,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Margin="0,20,0,0" Foreground="Black" Text="IP" />
</StackPanel>
<StackPanel Grid.Column="1">
<TextBlock Margin="0,20,0,0" />
<TextBlock Foreground="DarkGray" Text="192.168.2.1" />
</StackPanel>
</Grid>
</igRibbon:ApplicationMenu2010Item.Content>
</igRibbon:ApplicationMenu2010>
</igRibbon:XamRibbon.ApplicationMenu2010>
</igRibbon:XamRibbon>
</Grid>
</window>
I created a full-screen WPF Canvas, representing a time line. Only the visible part of the time line is composed, so (practically) no UI elements lie outside of the visible range.
I'm trying to add perspective to this time line using a Viewport3D. The result at the moment looks as follows:
You can scroll the time line left and right by dragging. Performance in the 2D version is great. However, once the canvas is placed inside a Viewport3D using Viewport2DVisual3D, performance drops drastically.
It's not like I'm rendering a complex mesh, where is this performance decrease coming from, and can I prevent it?
To give you an idea of how the 3D perspective was realized I'll add the XAML code here, unfortunately it doesn't work on its own.
<Grid Background="{StaticResource BackgroundBrush}">
<Viewport3D ClipToBounds="False">
<Viewport3D.Camera>
<PerspectiveCamera
Position="0 0 5"
LookDirection="0.4 0 -1"
UpDirection="0 1 0" />
</Viewport3D.Camera>
<ContainerUIElement3D>
<ModelUIElement3D>
<AmbientLight Color="White" />
</ModelUIElement3D>
</ContainerUIElement3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 2,3,0"
TextureCoordinates="0 0, 0 1, 1 1, 1 0">
<MeshGeometry3D.Positions>
<MultiBinding Converter="{StaticResource AspectRatioToPositions}">
<Binding ElementName="TimeLineContainer" Path="Width" />
<Binding ElementName="TimeLineContainer" Path="Height" />
</MultiBinding>
</MeshGeometry3D.Positions>
</MeshGeometry3D>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial
Viewport2DVisual3D.IsVisualHostMaterial="True"
Brush="White" />
</Viewport2DVisual3D.Material>
<Grid
x:Name="TimeLineContainer"
Width="1650" Height="600"
ClipToBounds="True"
Background="{StaticResource TimeLineBrush}"
Behaviors:MouseBehavior.LeftClickDragCommand="ActivityOverview:ActivityOverviewWindow.MouseDragged"
MouseWheel="OnMouseWheel"
MouseMove="OnMouseMoved">
<ActivityOverview:TimeLineControl x:Name="TimeLine" Focusable="True">
<ActivityOverview:TimeLineControl.CommandBindings>
<CommandBinding
Command="ActivityOverview:ActivityOverviewWindow.MouseDragged"
Executed="MoveTimeLine" />
</ActivityOverview:TimeLineControl.CommandBindings>
</ActivityOverview:TimeLineControl>
</Grid>
</Viewport2DVisual3D>
</Viewport3D>
</Grid>
When using Viewport2DVisual3D performance can be slow when you attempt to display content that is time-consuming to render. This seemed to be the case in my example.
For this reason, you can set the CacheMode of Viewport2DVisual3D.
<Viewport2DVisual3D>
<Viewport2DVisual3D.CacheMode>
<BitmapCache />
</Viewport2DVisual3D.CacheMode>
...
</Viewport2DVisual3D>
Starting from Windows Vista, anti-aliasing is enabled by default. Disabling this also helps in improving performance. It's weird this would have a big impact with such a simple mesh (two triangles), but on my PC, it does!
<Viewport3D ClipToBounds="False" RenderOptions.EdgeMode="Aliased">
Combining these two settings, I got great improvements.
Hi guys you can use <OrthographicCamera Position="0 0 5" LookDirection="0.4 0 -1" UpDirection="0 1 0" /> . Please check my code below
<Grid Background="{StaticResource BackgroundBrush}">
<Viewport3D ClipToBounds="False">
<Viewport3D.Camera>
<OrthographicCamera
Position="0 0 5"
LookDirection="0.4 0 -1"
UpDirection="0 1 0" />
</Viewport3D.Camera>
<ContainerUIElement3D>
<ModelUIElement3D>
<AmbientLight Color="White" />
</ModelUIElement3D>
</ContainerUIElement3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 2,3,0"
TextureCoordinates="0 0, 0 1, 1 1, 1 0">
<MeshGeometry3D.Positions>
<MultiBinding Converter="{StaticResource AspectRatioToPositions}">
<Binding ElementName="TimeLineContainer" Path="Width" />
<Binding ElementName="TimeLineContainer" Path="Height" />
</MultiBinding>
</MeshGeometry3D.Positions>
</MeshGeometry3D>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial
Viewport2DVisual3D.IsVisualHostMaterial="True"
Brush="White" />
</Viewport2DVisual3D.Material>
<Grid
x:Name="TimeLineContainer"
Width="1650" Height="600"
ClipToBounds="True"
Background="{StaticResource TimeLineBrush}"
Behaviors:MouseBehavior.LeftClickDragCommand="ActivityOverview:ActivityOverviewWindow.MouseDragged"
MouseWheel="OnMouseWheel"
MouseMove="OnMouseMoved">
<ActivityOverview:TimeLineControl x:Name="TimeLine" Focusable="True">
<ActivityOverview:TimeLineControl.CommandBindings>
<CommandBinding
Command="ActivityOverview:ActivityOverviewWindow.MouseDragged"
Executed="MoveTimeLine" />
</ActivityOverview:TimeLineControl.CommandBindings>
</ActivityOverview:TimeLineControl>
</Grid>
</Viewport2DVisual3D>
</Viewport3D>
If I put viewport3D inside Canvas my viewport3D is not visible anymore. If I remove Canvas then Viewport3D is visible again. What I'm doing wrong?
<Canvas Width="900" Height="524">
<Viewport3D Name="mainViewport" ClipToBounds="True" HitTestVisible="False">
<Viewport3D.Camera>
<PerspectiveCamera
FarPlaneDistance="3500"
LookDirection="0,0,1"
UpDirection="0,1,0"
NearPlaneDistance="1"
Position="0,0,0"
FieldOfView="66" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Canvas>
I think the ViewPort3D will end up in the upper left corner of the Canvas with a Width and Height of 0 since Canvas never stretches its Children. Try to add Canvas.Left and Canvas.Top at the positioning of your choise and then add Width and Height for your Viewport3D. If you want your Viewport3D to always fill the available space then Canvas is the wrong way to go.
<Canvas Width="900" Height="524">
<Viewport3D Canvas.Left="100"
Canvas.Top="100"
Width="200"
Height="200"
Name="mainViewport"
ClipToBounds="True"
IsHitTestVisible="False">
<Viewport3D.Camera>
<PerspectiveCamera
FarPlaneDistance="3500"
LookDirection="0,0,1"
UpDirection="0,1,0"
NearPlaneDistance="1"
Position="0,0,0"
FieldOfView="66" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Canvas>
I'm wondering if anyone knows if it's possible in XAML to have a ListBox whose DataTemplate defines the ListBoxItem as a 3d element. Something along the lines of:
<ListBox x:Name="lst3D" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Viewport3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="40" Axis="0, 1, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 0 2 3"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="AliceBlue"/>
</Viewport2DVisual3D.Material>
<Label>Hello, 3D</Label> // we'd like to databind controls like this one
</Viewport2DVisual3D>
</Viewport3D>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBoxItem />
<ListBoxItem />
<ListBoxItem />
</ListBox>
Anyone seen this sort of thing done/have any advice?
Greatly appreciated,
bv
Replace the button with a content control such as,
<ContentControl Content="{Binding}" />
It also looks like the Viewpord3D doesn't request layout space so I needed to wrap it in a <Grid Height="100" Width="100">...</Grid> to see anything.
There's a couple of ways to do this.
You can change the DataTemplate to a ControlTemplate, and have it apply to all the items in the ListBox. But you cannot bind it to a specific data type.
The other option is move the DataTemplate to a resources section, and set the DataType to the type of the item you wish to display. Then you can use binding to bind to a property of the item etc.