Wpf 自定义面板实现期间ItemsControl中附加属性的值
我实现了自定义面板工具架,该工具架根据附加的属性工具架排列子对象。精确:Wpf 自定义面板实现期间ItemsControl中附加属性的值,wpf,wpf-controls,Wpf,Wpf Controls,我实现了自定义面板工具架,该工具架根据附加的属性工具架排列子对象。精确: DataTemplate中的TextBlock不是ItemsPanel测量和排列的元素 您必须在items容器(即ItemContainerStyle中的ContentPresenter)上设置attached属性: <ItemsControl ItemsSource="{Binding Packs}"> <ItemsControl.ItemsPanel> <Items
DataTemplate中的TextBlock不是ItemsPanel测量和排列的元素 您必须在items容器(即ItemContainerStyle中的ContentPresenter)上设置attached属性:
<ItemsControl ItemsSource="{Binding Packs}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:Shelf/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="local:Shelf.Exact" Value="{Binding Number}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
值得一提的链接:这解释了问题。
<ItemsControl ItemsSource="{Binding Path=Packs}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:Shelf />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock local:Shelf.Exact="{Binding Path=Number}" Text="{Binding Path=Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<local:Shelf Grid.Column="1">
<TextBlock local:Shelf.Exact="223">Test</TextBlock>
<TextBlock local:Shelf.Exact="332">Test</TextBlock>
<TextBlock local:Shelf.Exact="443">Test</TextBlock>
</local:Shelf>
<ItemsControl ItemsSource="{Binding Packs}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:Shelf/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="local:Shelf.Exact" Value="{Binding Number}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>