2つのテンプレートがあります。1つはテキストボックス用で、もう1つはリストビュー用です。どちらも、デフォルトの長方形ではなく、角を丸くするために使用されます。私のテキストボックスには、テキストを表示するために「ScrollViewer x:Name = "PART_ContentHost」行が必要でしたが、リストビューでは機能しません。リストビューのテンプレートを取り出すと、サンプルのlistviewitem(もの)が表示されます。それ以外の場合コードビハインドに追加した他のアイテムは表示されません。これを機能させるためにxamlに何が欠けていますか?
これが私のxamlです:
<!-- Design Templates to set the borders of the controls-->
<UserControl.Resources>
<ControlTemplate x:Key="TextBoxTemplate" TargetType="TextBox">
<Border BorderBrush="Black" BorderThickness="1,1,1,.5" CornerRadius="7">
<ScrollViewer x:Name="PART_ContentHost" ></ScrollViewer>
</Border>
</ControlTemplate>
<ControlTemplate x:Key="ListViewTemplate" TargetType="ListView">
<Border BorderBrush="Black" BorderThickness=".5,1,1,1" CornerRadius="7">
</Border>
</ControlTemplate>
</UserControl.Resources>
<!-- Controls -->
<Grid Height="270" Width="400">
<StackPanel Width="390">
<TextBox Height="35" Name="InputTextbox" Template="{StaticResource TextBoxTemplate}" VerticalContentAlignment="Center" TextChanged="InputTextbox_TextChanged"></TextBox>
<ListView Height="235" Name="ResultsListView" Template="{StaticResource ListViewTemplate}" SelectionChanged="ResultsListView_SelectionChanged">
<ListViewItem Content="stuff"></ListViewItem>
</ListView>
</StackPanel>
</Grid>