WPF ItemsPanelTemplate不允许添加简单的UIElement
我正在尝试设置控件项的样式,并使用此XAML:WPF ItemsPanelTemplate不允许添加简单的UIElement,wpf,mvvm,Wpf,Mvvm,我正在尝试设置控件项的样式,并使用此XAML: <DataTemplate x:Key="DatatemplatePlateItemContainer"> <Grid x:Name="PlateItemContainer"> <!-- Does recursive ItemTemplate selection --> <ItemsControl ItemsSource="{Binding Path
<DataTemplate x:Key="DatatemplatePlateItemContainer">
<Grid x:Name="PlateItemContainer">
<!-- Does recursive ItemTemplate selection -->
<ItemsControl ItemsSource="{Binding Path=Children}"
ItemTemplateSelector="{StaticResource TemplateselectorPlateItem}">
<ItemsControl.ItemContainerStyle>
<Style>
<Style.Setters>
<Setter Property="Grid.Row" Value="{Binding Path=GridRow}"/>
<Setter Property="Grid.Column" Value="{Binding Path=GridColumn}"/>
</Style.Setters>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- This line will not let the ItemsControl to load -->
<Rectangle Grid.Row="0" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="4"/>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</DataTemplate>
您的XAML无效。ItemsPanel不能有硬编码的子项。您想做什么?我想在网格的每一侧都有矩形,以检测鼠标在每个矩形上的拖动,并检测当前项的左/右/上/下TM的拖放逻辑,因此更改
ItemsControl.Template
您的XAML无效。ItemsPanel不能有硬编码的子项。你想做什么?我想在网格的每一侧都有矩形,以检测鼠标在每个矩形上的拖动,并检测当前项的左/右/上/下TM的拖放逻辑,因此更改ItemsControl.Template
A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
A first chance exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Add value to collection of type 'System.Windows.Controls.UIElementCollection' threw an exception.
An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Add value to collection of type 'System.Windows.Controls.UIElementCollection' threw an exception.