2015-06-21 74 views
1

我想制作ToggleButtons的列表。他们每个人都被绑定到一个弹出窗口。 我有一个问题,所以我试图把所有内容StackPanel。 但是,现在,当应用程序正在运行时,它将在ToggleButton之后显示一个空白空间(用于Popup)。我能做些什么来解决这个问题?如何使用绑定到xaml wpf中的ListView中的ToggleButton的Popup?

我刚刚添加了两张图片: 第一个是上传页面的时候。 第二个是当我向下滚动页面。

enter image description here enter image description here

<ListView x:Name="ListOfRecipes" HorizontalAlignment="Center" VerticalAlignment="Top" ItemsSource="{Binding}" Grid.Row="1" Margin="25,0.333,25,35" ScrollViewer.VerticalScrollMode="Enabled" Grid.RowSpan="5" > 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <ToggleButton x:Name="RecipeButton" Grid.Row="1" BorderBrush="#FF65C365" VerticalAlignment="Center" HorizontalAlignment="Center" Click="Button_Click" Height="150" Width="328" > 
         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Height="128" Width="328"> 
          <Image Source="{Binding Path=ImageUri}" Height="128" Width="128" Margin="0,6,0,-5.667" /> 
          <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Height="128" Width="192"> 
           <TextBlock Height="25" Width="190" Foreground="#FF6FDC13" Text="{Binding Name}" VerticalAlignment="Top" /> 
           <Image Name="YesOrNoImage" Source="{Binding Path=YesOrNoImage}" Width="102" Height="102" HorizontalAlignment="Center" VerticalAlignment="Bottom"/> 
          </StackPanel> 
         </StackPanel> 
        </ToggleButton> 
        <Popup IsOpen="{Binding IsChecked, ElementName=RecipeButton, Mode=TwoWay}" Height="514" Width="328" VerticalAlignment="Center" Name="PopupOne" Grid.Row="1" Grid.RowSpan="4" IsLightDismissEnabled="True" IsHoldingEnabled="False" ScrollViewer.VerticalScrollMode="Enabled" > 
         <Border BorderBrush="#FF65C365" BorderThickness="1" Background="White" Height="514" Width="328"> 
         <StackPanel Orientation="Vertical" ScrollViewer.VerticalScrollMode="Enabled"> 
          <Image Source="{Binding Path=ImageUri}" Height="328" Width="328" /> 
          <TextBlock Foreground="#FF6FDC13" Text="{Binding Name}" HorizontalAlignment="Left" FontSize="28" /> 
           <ScrollViewer VerticalScrollMode="Enabled" > 
            <TextBlock Foreground="Black" Text="{Binding RecipeText}" HorizontalAlignment="Left" FontSize="18" /> 
           </ScrollViewer> 
         </StackPanel> 
        </Border> 
       </Popup> 
       </Grid> 
      </DataTemplate> 

     </ListView.ItemTemplate> 

    </ListView> 
+0

用'Grid'替换'StackPanel' – dkozl

+1

我也试过了。同样的问题。 – Nnp

+0

你能提供一张“空白空间”的照片吗? –

回答

3

看来这个问题是由<PopUp Height=514/> 造成测试,将高度设置为0,看它是否解决了国内空白。如果是这样,您可以使用可见性转换器将可见性绑定到PopUp.IsOpen(我认为蓝色MVVM有一个)。由于我目前对转换器的教育不是很好,所以我想出了一个解决方法。

public RecipeButton : INotifyPropertyChanged { 
    // Need to implement INotifyPropertyChanged logic on IsCheckedVisiblity for UI to be notified of visibility changes 
    public Visibility IsCheckedVisibility { get; set; } 
    private bool _IsChecked; 
    public bool IsChecked { 
     get { return _IsChecked }; 
     set { _IsChecked = value; 
      this.IsCheckedVisibility = value == true ? Visiblity.Collapsed : Visiblity.Visible; 
     } 

} 

<PopUp Visibility = "{Binding IsCheckedVisibility}"/>

让我知道,如果不工作,我会尝试别的东西。

+1

OMG!完善!非常感谢!!!!!我刚刚将高度更改为0,它可以工作!!!!!!!!!!!!!!!!非常感谢!!!! – Nnp

+1

我想投票你的答案,但我没有足够的声誉呢=]谢谢,谢谢,谢谢! =] – Nnp

+0

没问题,交配。祝你的应用程序好运! –