在針對Windows Store 8.1和Windows Phone 8.1的Windows通用應用8.1平臺中,我需要隱藏文本塊,該文本塊在收集綁定時顯示「列表爲空」到ListView
有一些項目,我需要顯示這個文本塊,只要收集是空的。如何在通用Windows應用程序8.1中顯示和隱藏文本塊
請爲此建議一個解決方案。
到目前爲止,我已經嘗試過這種方式,但是在集合中有項目的時候它不起作用TasksEmptyMsg仍然顯示「列表爲空」。
<Page
x:Class="ToDoer.Pages.Task"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ToDoer.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView x:Name="Tasks"
ItemsSource="{Binding Tasks}"
SelectedItem="{Binding SelectedTask,Mode=TwoWay}"
ItemTemplate="{StaticResource TasksItemTemplate}"
Padding="24,24">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding TaskSelectionChanged}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ListView>
<TextBlock x:Name="TasksEmptyMsg"
Text="The list is empty"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="Collapsed"
Style="{StaticResource GroupHeaderTextBlockStyle}">
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding ElementName=Tasks,Path=Items.Count}"
Value="0">
<core:ChangePropertyAction TargetObject="{Binding ElementName=TasksEmptyMsg}"
PropertyName="Visibility"
Value="Visible"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</TextBlock>
<!--Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" IsHitTestVisible="False" />-->
</Grid>
<Page.BottomAppBar>
<CommandBar>
<AppBarButton Icon="Add"
Label="add todo"
Command="{Binding AddTask}"/>
</CommandBar>
</Page.BottomAppBar>
</Page>
當集合中沒有項目時工作正常。
問題:顯示「列表是空的」,即使它不是。
沒有二傳手,StateTriggers性能上的VisualState在Windows應用程序萬能,我得到一個錯誤的XAML ,看起來像你發佈的解決方案是Windows通用平臺,我正在使用Windows通用應用程序 –
@AbdulMateenMohammed是的,我認爲他們也在Win-RT中,不難改變這一點,給我一點時間。 – Romasz
@AbdulMateenMohammed帶轉換器的版本,適用於WinRT。 – Romasz