在Text上放置TextBox

时间:2017-03-12 10:16:15

标签: wpf xaml

我想在Canvas上均匀分布18个文本框。但是,<?php $confirm_ref = "http://www.example.com/?x=test&test"; $pp_refz = array_filter(preg_split('(https://|http://|www.|&|=|/|-|\?)', $confirm_ref)); $domains = array("bla.com","bla1.net","bla2.com","bla3.com","bla4.tk","blabla.com","blabla1.com","blabla3.net","example.com"); $strings = array("DIg","AsD","w5L","ptp","ptp.php","hps.php","hide.php","p"); //print_r(array_values($pp_refz)); $big = array_merge($domains, $strings); //print_r(array_values($big)); //Check function: if(array_intersect($pp_refz,$big) == true) { echo "gotcha"; } ?> 的{​​{1}}属性未设置(它们都出现在画布的左侧)。为什么这段代码不起作用?

Left

1 个答案:

答案 0 :(得分:4)

TextBlock不是ItemsPanelTemplate中Canvas的直接子项,因此设置Canvas.Left无效。

您必须使用Setter声明ItemContainerStyle,该Setter绑定项容器的Canvas.Left属性(即ContentPresenter,为每个项目创建并添加为ItemsPanel的子项):

<ItemsControl ...>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas .../>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left">
                <Setter.Value>
                    <MultiBinding>
                        ...
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>