2016-03-28 144 views
0

如何向一個xaml顯示一個listview? on mainpage.xaml,我只想顯示綁定「Kata」。另一個xaml我想顯示綁定「卡塔」和「說明」。將一個listview綁定到多個xaml

此MainPage.xaml中

<ListView x:Name="listView" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="520" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Grid.Row="2" Background="#33FFFFFF"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <TextBlock Text="{Binding Kata}" Tapped="TextBlock_Tapped_1" FontSize="26.667" /> 
       </StackPanel> 
      </DataTemplate> 

     </ListView.ItemTemplate> 
    </ListView> 

另一個XAML。

<ListView x:Name="dictionary_list" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="620" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Background="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <TextBlock Text="{Binding Kata}" FontSize="26.667" Foreground="White" TextAlignment="Center" /> 
        <TextBlock Text="{Binding Description}" Foreground="White" /> 

       </StackPanel> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 

回答

0

使用用戶控件和一個的DependencyProperty是否顯示或不說明字段 ListViewUserContrl.xaml

<UserControl 
    x:Class="Listview.ListViewUserContrl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Listview" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" 
    d:DesignWidth="400" 
    x:Name="ListViewUserControl"> 

    <Grid> 
     <ListView x:Name="dictionary_list" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="620" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Background="{ThemeResource AppBarItemDisabledForegroundThemeBrush}"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <StackPanel> 
         <TextBlock Text="{Binding Kata}" FontSize="26.667" Foreground="White" TextAlignment="Center" /> 
         <TextBlock Text="{Binding Description}" Visibility="{Binding ElementName=ListViewUserControl,Path=DescriptionVisibility}" Foreground="White" /> 

        </StackPanel> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 
    </Grid> 
</UserControl> 

ListViewUserContrl.xaml.cs

public sealed partial class ListViewUserContrl : UserControl 
    { 
     public static readonly DependencyProperty DescriptionVisibilityProperty = 
      DependencyProperty.Register("DescriptionVisibility", typeof(Visibility), typeof(ListViewUserContrl), 
       new PropertyMetadata(Visibility.Collapsed)); 
     public Visibility DescriptionVisibility 
     { 
      get { return (Visibility)GetValue(DescriptionVisibilityProperty); } 
      set { SetValue(DescriptionVisibilityProperty, value); } 
     } 
     public ListViewUserContrl() 
     { 
      this.InitializeComponent(); 
     } 
    } 

添加到您的像這樣的頁面

<local:ListViewUserContrl DescriptionVisibility="Visible"/> 
相關問題