0
我有以下的ControlTemplate,如下圖所示,我想避免硬編碼的圖像的HIGHT和寬度,而不是我想圖像控件的高度和寬度結合模板內綁定
<Image Source="/Rotate.Pictures;component/Images/error.png"
Stretch="Uniform"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="14"
Width="14"/>
給TextBlock的Text(TextBlock named「ErrorText」)屬性path =「Height」。圖像的高度和寬度都應該綁定到TextBlock的文本高度屬性的高度值
有誰知道我該如何實現這一目標?
模板:
<Grid IsSharedSizeScope="True">
<Grid.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<AdornedElementPlaceholder>
<Border BorderBrush="Red" BorderThickness="2"/>
</AdornedElementPlaceholder>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="/Rotate.Pictures;component/Images/error.png" Stretch="Uniform" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="14"
Width="14"/>
<TextBlock x:Name="ErrorText" Text="{Binding ErrorContent}" Foreground="Red"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
之前指定Grid.Column 1我猜你真正想要的是在ErrorContent一個DataTrigger那臺圖像可見性在ErrorContent不爲空時可見。 – Clemens