I was trying to design a template for binding a collection and was getting this error when I tried
to Bind text block to the property.
Problem:
I could not get this to compile it kept throwing the error. - The property 'VisualTree' is set more than once
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Grid.Column="0" Content="{Binding Path=Type}" />
<TextBox Grid.Column="1" Text="{Binding Path=CountryPrefix}" />
<TextBox Grid.Column="2" Text="{Binding Path=Number}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Solution:
I was missing the layout panel, ie. StackPanel
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Grid.Column="0" Content="{Binding Path=Type}" />
<TextBox Grid.Column="1" Text="{Binding Path=CountryPrefix}" />
<TextBox Grid.Column="2" Text="{Binding Path=Number}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
No comments:
Post a Comment