- paevensonKratos
- Posts: 9
- Joined:
ComboBox in DataTemplate inside Unity
Here is the code:
XAML
DataTemplate
ListBox
When i try to view it inside Unity the combo box is empty:
This thread sounded like a similar problem....viewtopic.php?f=3&t=344
What am I doing wrong?
XAML
DataTemplate
Code: Select all
<Grid.Resources>
<DataTemplate x:Key="InteractionTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Height="10" Text="{Binding Index}" Grid.Column="0" />
<TextBlock Text="{Binding ObjectName}" Margin="5, 0, 5, 0" Grid.Column="1"/>
<TextBlock Text="{Binding ObjectState}" Margin="5, 0, 5, 0" Grid.Column="2"/>
<ComboBox x:Name="ModelTypeComboBox" Height="24" Width="79" Grid.Column="3">
<ComboBoxItem x:Name="ModelTypeBoxUpper" Content="Upper" IsSelected="True"/>
<ComboBoxItem x:Name="ModelTypeBoxLower" Content="Lower"/>
<ComboBoxItem x:Name="ModelTypeBoxBuccal" Content="Buccal"/>
</ComboBox>
</Grid>
</DataTemplate>
</Grid.Resources>
Code: Select all
<ListBox Height="196" ItemsSource="{Binding ActionCollection, ElementName=Root}" ItemTemplate="{StaticResource InteractionTemplate}">
This thread sounded like a similar problem....viewtopic.php?f=3&t=344
What am I doing wrong?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: ComboBox in DataTemplate inside Unity
The ListBox.ItemsSource has a Binding that points to the ActionCollection property of the element named "Root".
Are you sure that "Root" element exposes the "ActionCollection" property?
Which type of element is "Root"?
Maybe you set a View Model in the Root element, and your binding should look just like this:
Are you sure that "Root" element exposes the "ActionCollection" property?
Which type of element is "Root"?
Maybe you set a View Model in the Root element, and your binding should look just like this:
Code: Select all
ItemsSource="{Binding ActionCollection}"
- paevensonKratos
- Posts: 9
- Joined:
Re: ComboBox in DataTemplate inside Unity
My binding is working properly. Root is just pointing to the Noesis.UserControl. Iv'e tried this code as well.
It doesnt work inside of Unity. I can see the combo boxes just fine in Blend, fully populated, but in Unity they are still blank.Hi Rob,
Based on your xaml, I tried two options to assign a DataTemplate to an item: using the ListBoxItem.ContentTemplate and using the ListBox.ItemTemplate; both worked well.
Is this what you want to achieve?Code: Select all<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid.Resources> <DataTemplate x:Key="ModelLayerTemplate"> <Grid HorizontalAlignment="Left" Height="60" Margin="0,0,0,0" VerticalAlignment="Top" Width="168"> <Rectangle RadiusY="5" RadiusX="5" Fill="#BF6C87CC"/> <TextBox x:Name="ModelNameTextBox" Margin="32.5,5,0,0" TextWrapping="Wrap" Text="Model Name" FontSize="12" Background="#FF5368A1" Foreground="#FFDADADA" Height="25" VerticalAlignment="Top" Width="130" HorizontalAlignment="Left" BorderBrush="{x:Null}"/> <ComboBox x:Name="ModelTypeComboBox" Height="24" Margin="32,0,0,5" VerticalAlignment="Bottom" Width="79" HorizontalAlignment="Left"> <ComboBoxItem x:Name="ModelTypeBoxUpper" Content="Upper" IsSelected="True"/> <ComboBoxItem x:Name="ModelTypeBoxLower" Content="Lower"/> <ComboBoxItem x:Name="ModelTypeBoxBuccal" Content="Buccal"/> </ComboBox> <ToggleButton x:Name="ModelToggleVisibilityButton" Content="X" HorizontalAlignment="Left" Margin="3,0,0,0" Style="{DynamicResource ToggleVisibilityEye}" Width="25" IsChecked="True" VerticalAlignment="Center" Height="25"/> </Grid> </DataTemplate> </Grid.Resources> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <ListBox> <ListBoxItem Content="Hello" ContentTemplate="{StaticResource ModelLayerTemplate}"/> </ListBox> <ListBox ItemTemplate="{StaticResource ModelLayerTemplate}" Margin="0,10,0,0"> <TextBlock Text="Item1"/> </ListBox> </StackPanel> </Grid>
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: ComboBox in DataTemplate inside Unity
If you are using your own UserControl as source of the items collection, you can try the following:
This scenario is working for me.
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DataTemplateTest"
x:Name="Root">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="InteractionTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Index}" Grid.Column="0" VerticalAlignment="Center"/>
<TextBlock Text="{Binding ObjectName}" Margin="5, 0, 5, 0" Grid.Column="1" VerticalAlignment="Center"/>
<TextBlock Text="{Binding ObjectState}" Margin="5, 0, 5, 0" Grid.Column="2" VerticalAlignment="Center"/>
<ComboBox x:Name="ModelTypeComboBox" Height="24" Grid.Column="3">
<ComboBoxItem x:Name="ModelTypeBoxUpper" Content="Upper" IsSelected="True"/>
<ComboBoxItem x:Name="ModelTypeBoxLower" Content="Lower"/>
<ComboBoxItem x:Name="ModelTypeBoxBuccal" Content="Buccal"/>
</ComboBox>
</Grid>
</DataTemplate>
</Grid.Resources>
<ListBox Height="196" HorizontalAlignment="Center"
ItemsSource="{Binding ActionCollection, ElementName=Root}"
ItemTemplate="{StaticResource InteractionTemplate}"/>
</Grid>
</UserControl>
Code: Select all
[Noesis.Extended]
public class DataItem : Noesis.BaseComponent
{
public uint Index { get; set; }
public string ObjectName { get; set; }
public string ObjectState { get; set; }
}
[Noesis.Extended]
[Noesis.UserControlSource("Assets/Test/_Test.xaml")]
public class DataTemplateTest : Noesis.UserControl
{
public Noesis.Collection ActionCollection { get; private set; }
public DataTemplateTest()
{
ActionCollection = new Noesis.Collection();
ActionCollection.Add(new DataItem
{
Index = 0,
ObjectName = "Jon",
ObjectState = "Active"
});
ActionCollection.Add(new DataItem
{
Index = 1,
ObjectName = "Pet",
ObjectState = "Inctive"
});
ActionCollection.Add(new DataItem
{
Index = 2,
ObjectName = "Ras",
ObjectState = "Active"
});
}
}
Who is online
Users browsing this forum: No registered users and 3 guests