0
我有一個App.xaml中的模板:模板設計問題
<Application.Resources>
<!-- template for recent history -->
<DataTemplate x:Key="ListViewModelTemplate"> <!-- for recent recepies-->
<Grid Width="400" Height="80" VerticalAlignment="Center">
<StackPanel Orientation="Vertical">
<Border CornerRadius="0" x:Name="brdTesat" BorderBrush="Black" BorderThickness="1" Width="80" Height="80">
<Border.Background>
<ImageBrush x:Name="backgroundImaageBrush" Stretch="Fill">
<ImageBrush.ImageSource>
<BitmapImage x:Name="bmapBackground" UriSource="{Binding imageUriPath}" >
</BitmapImage>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
</Border>
<StackPanel>
<TextBlock TextAlignment="Left" Margin="7,4,4,4" Text="{Binding title}" TextWrapping="Wrap"></TextBlock>
<TextBlock TextAlignment="Left" Margin="7,4,4,4" Text="{Binding subTitle}" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
,並試圖把它在一個列表框顯示..問題是,列表框,雖然綁定到數據時,沒有按」不知道如何使用模板。這裏是我的列表框的定義:
<ListBox x:Name="recepiesList" ItemsSource="{Binding recepiesList}" ItemTemplate="{StaticResource ListViewModelTemplate}" >
,如果我在的地方定義模板,像
<ListBox.Template><DataTemplate><TextBlock text={Binding title} /></DataTemplate></ListBox.Template>
列表框中的偉大工程,但我需要糾正我Application.Resources之一。我怎麼能這樣做?