Windows Phone 8.1:如果文本块为空,则隐藏堆栈面板



我的XAML代码如下我的整个 XAML

<Page
    x:Class="App13.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App13"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:converter="using:App13"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <converter:BooleanToVisibilityConvertor x:Key="visibilityConverter"/>
    </Page.Resources>

    <Grid  Margin="0,30.333,0,-0.333" Background="Black"  >
        <!--<Button Margin="0,-105,0,563" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollMode="Enabled" x:Name="one" Content="Getdata"    RenderTransformOrigin="0.367,-0.585" Height="92" Width="112" Click="Button_Click"/>-->
          <ListView IsItemClickEnabled="True" IsEnabled="True" ItemClick="listview1_ItemClick" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Visible" x:Name="listview1" ItemsSource="{Binding Taxi}" FontSize="17" Margin="10,0,-10,0">
<ListView.Items>
                <StackPanel Background="Blue">
                 <TextBlock Text="eqweqwe" Foreground="AntiqueWhite"></TextBlock>
                    <TextBlock Foreground="Aqua" Text="sadwdasdasdasd"></TextBlock>
                </StackPanel>
            </ListView.Items>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                            <Border Tapped="Border_Tap" Height="90">
                            <StackPanel  x:Name="ParentStackPanel" Width="380" Margin="0,5,0,5">

                            <StackPanel Margin="0,-80,0,0" Background="Black" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left">
                                <Image  Width="48"  
                 Height="48"  
                 Source="{Binding Icon}" 
                  />

                            </StackPanel>
                                <StackPanel Name="expand" Background="White" Height="220" >
                                    <StackPanel   Orientation="Horizontal" Margin="10,10,0,0" Visibility="{Binding Invoice.Minimum_Fare, Converter={StaticResource visibilityConverter}}">
                                        <TextBlock AllowDrop="True" Grid.Column="1" Margin="50,0,0,0" HorizontalAlignment="Left" FontSize="10" Foreground="Black"  Text="Approx Travel Time" ></TextBlock>
                                        <TextBlock Name="tb"  Grid.Column="2"  HorizontalAlignment="Right" AllowDrop="True" FontSize="6" Foreground="Black" Width="204" Text="{Binding Invoice.Minimum_Fare}" >
                                        </TextBlock>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="10,3,0,0" >

                                        <TextBlock Width="183"  Margin="50,0,0,0" FontSize="16" Foreground="Black" Text="Minimum Fare"></TextBlock>
                                        <TextBlock   FontSize="16"  Foreground="Black" Text="{Binding Invoice.Minimum_Fare}" Width="131">

                                        </TextBlock>
                                    </StackPanel>
                            <StackPanel Margin="0,5,0,5" Height="5"  Grid.Row="1" Background="Aqua" x:Name="something">
                          </StackPanel>
                            </StackPanel>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>

使用可视化状态管理器或一些前端技术,如果文本块文本为空,我想隐藏堆栈面板

我莫尔是这个

public class Example {
 public string CompanyName { get; set;}
 public string Invoice { get; set; }
 public string Lat { get; set; } 
public string Lng { get; set; }
 }

通过我不知道如何将可见性与堆栈面板绑定

您可以编写转换器来隐藏/显示堆栈面板

public class BooleanToVisibilityConvertor: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if(value!=null)
        {
            if (!string.IsNullOrEmpty(value.ToString()))
            {
                return Visibility.Visible;
            }
        }
            return Visibility.Collapsed;
    }
    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

在 xaml 中添加转换器

<Page
x:Class="App1.MainPage"
xmlns:converter="using:App1">
<Page.Resources>
    <converter:BooleanToVisibilityConvertor x:Key="visibilityConverter"/>
</Page.Resources>
 <StackPanel Background="Aqua" Height="200" Orientation="Horizontal" Margin="10,3,0,0" Visibility="{Binding Invoice, Converter={StaticResource visibilityConverter}}">
            <TextBlock  FontSize="16" Text="{Binding Invoice}" Name="tb" Height="300" Width="300" Foreground="Black" >
            </TextBlock>
        </StackPanel>

我有硬编码的文本值用于测试。您可以使用绑定。

检查并让我知道是否有任何问题。

您无法在 Windows Phone 8 中使用可视状态执行此操作。我建议你创建一个简单的 StringToVisibilityConverter(返回 Visibility.Collapsed on 空字符串)并使用它来绑定你的 StackPanel 可见性。

<StackPanel  Visibility="{Binding Path=stcVisiblity}" >   
    <TextBlock  FontSize="16"  Foreground="Black" Text="{Binding Invoice}">
    </TextBlock>
</StackPanel>

和类

   public class Example {
 public string CompanyName { get; set;}
 public string Invoice { get; set; }
 public string Lat { get; set; } 
public string stcVisiblity { get; set; }
 public string Lng { get; set; }
 }

和比代码像这样的东西来编码,您可以根据需要绑定此值:

stcVisiblity = "可见";或 stcVisiblity ="崩溃";

最新更新