我尝试将width和height属性设置为我的数据模板控件,但我的控件保持其默认大小。
<ItemsControl Grid.Row="1" x:Name="containerUsers" ItemsSource="{Binding ValidUsers}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" AllowDrop="True" ClipToBounds="False" DragEnter="panelUsers_DragEnter" Drop="panelUsers_Drop" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<my:PictureLabelControl Width="20" Height="50" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
实际上我有三个这样的面板,我希望我可以通过拖放来改变控件的大小。
<UserControl x:Class="VHTService.Wfm.View.PictureLabelControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Cursor="Hand" Focusable="True" Margin="3">
<Grid>
<Grid Name="grid1">
<Label Content="{Binding LabelText}" Focusable="True" FontSize="12" FontWeight="Normal" HorizontalContentAlignment="Center"
Name="lblPicture" VerticalContentAlignment="Center" Height="26" VerticalAlignment="Bottom" />
<Image Source="{Binding Picture}" Focusable="True" Name="imgAvatar" Stretch="Uniform" Margin="0,0,0,26" GotFocus="imgAvatar_GotFocus"
LostFocus="imgAvatar_LostFocus" />
</Grid>
</Grid>
答案 0 :(得分:1)
我制作了以下示例窗口,项目遵循给定的大小。你可以发布PictureLabelControl吗?我认为错误就在那里。
<Window
x:Class="Project1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Height="350"
Width="525">
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
IsItemsHost="True"
AllowDrop="True"
ClipToBounds="False"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock
Background="Gray"
Text="{Binding}"
Width="50"
Height="50"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Items>
<System:String>foo1</System:String>
<System:String>foo2</System:String>
</ItemsControl.Items>
</ItemsControl>
</Window>