我尝试设置ListBoxItem的样式。在第二个TextBox(我只是绑定PhoneNumber)中,文本正确对齐。但在第二个(我在其中使用TextBox StaticResource和multibinding)verticalAlignment不起作用 - 它根本不会改变文本。
<Style x:Key="ItemStyle" TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel>
<TextBlock Style="{StaticResource TextBlockStyle}"
VerticalAlignment="Center"
DockPanel.Dock="Left"></TextBlock>
<TextBlock Text="{Binding PhoneNumber}"
VerticalAlignment="Center"
DockPanel.Dock="Right"
HorizontalAlignment="Right"></TextBlock>
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Trigger>
这是我的TextBlockStyle:
<Style x:Key="TextBlockStyle" TargetType="TextBlock">
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Text">
<Setter.Value>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Name"/>
<Binding Path="LastName" />
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
</Style>
答案 0 :(得分:0)
我解决了。而不是放:
<Setter Property="VerticalAlignment" Value="Center"></Setter>
TextBlockStyle中的我应该把它放在ItemStyle中。