次のテンプレートでは、色付きのボックスに動的情報が表示されます。
ただし、ボックスは常にDockPanel/画面の全幅です。
Border 要素に固定幅を配置することもできますが、非常に長い顧客名が途切れる可能性があります。
<table>
HTMLの要素のように、コンテンツの幅に基づいて幅を拡大および縮小する必要があることを Border に伝えるにはどうすればよいですか?
HTML:
<table>
<tr>
<td style="background-color: #eee; padding: 5px">
the table will be as wide as this text
</td>
</tr>
</table>
XAML:
<Window.Resources>
<DataTemplate x:Key="CustomerTemplateShow">
<Border CornerRadius="5" Background="#eee" Padding="5">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<DockPanel LastChildFill="False" Margin="10">
<ContentControl
DockPanel.Dock="Top"
Content="{Binding SelectedCustomer}"
ContentTemplate="{StaticResource CustomerTemplateShow}"/>
</DockPanel>