Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 自定义面板实现期间ItemsControl中附加属性的值_Wpf_Wpf Controls - Fatal编程技术网

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>