我尝试在Scrollviewer中动态构建切片。所有数据都来自通过网络服务填充的List<myclass>
。
DataTemplate应该是一个带有两个标签和一个图片的网格我现在尝试了不同的方法但看起来我到目前为止还不理解一些基础知识。有人可以帮我提供一个例子吗?
答案 0 :(得分:0)
ScrollViewer
是一个内容控件。要显示切片等项目列表,您需要使用项目控件的ItemsSource
属性,例如ListView
或ItemsControl
。
换句话说,您需要使用ItemsSource
语法将列表绑定到ListView
的{{1}},并确保设置视图的{Binding ...}
,并且您的列表是该DataContext
类的一部分,通常为DataContext
。
答案 1 :(得分:0)
仅供参考,感谢您的提示/帮助。以下是解决方案。我希望提供它是正确和可靠的。
<ScrollViewer Grid.Row="1" x:Name="VisitPlanScrollView" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" Margin="20,0,20,0">
<ItemsControl Name="VisitPlanItems" ItemsSource="{Binding}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" ></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Controls:Tile x:Name="VisitPlanTile" Click="TileClick" >
<Controls:Tile.Style>
<Style TargetType="Controls:Tile">
<Setter Property="IsEnabled" Value="True"></Setter>
<Setter Property="Background" Value="#FF0068B3"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding bIsEmptyPlan}" Value="True">
<Setter Property="IsEnabled" Value="False"></Setter>
<Setter Property="Background" Value="DarkGray"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Controls:Tile.Style>
<Grid HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Label Content="{Binding VisitPlanTitelSub}" Foreground="White" FontSize="16" HorizontalAlignment="Center"></Label>
<Label x:Name="ibsSubTitle" Grid.Row="1" Content="{Binding VisitPlanID}" Foreground="White" HorizontalAlignment="Center"></Label>
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
<Label x:Name="TileDetailCount" Content="{Binding VisitPlanDetailCount}" Foreground="White" FontWeight="Bold" HorizontalAlignment="Center" ></Label>
<Button x:Name="button_CreatenewReminderVPTile" Click="button_CreatenewReminderVPTile_OnClick" ToolTip="Erstellt eine neue Wiedervorlage zu diesem Besuchsplan." >
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#FF0068B3" ></Setter>
<Setter Property="BorderBrush" Value="#FF0068B3"></Setter>
<Setter Property="Background" Value="#FF0068B3" ></Setter>
<Setter Property="BorderBrush" Value="#FF0068B3"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding bIsEmptyPlan}" Value="True">
<Setter Property="Background" Value="DarkGray" ></Setter>
<Setter Property="BorderBrush" Value="DarkGray"></Setter>
<Setter Property="Foreground" Value="DarkGray"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Visibility" Value="Collapsed"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<iconPacks:PackIconModern Kind="Notification" Foreground="White">
<iconPacks:PackIconModern.Style>
<Style TargetType="iconPacks:PackIconModern">
<Setter Property="Background" Value="#FF0068B3" ></Setter>
<Setter Property="BorderBrush" Value="#FF0068B3"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding bIsEmptyPlan}" Value="True">
<Setter Property="Background" Value="DarkGray" ></Setter>
<Setter Property="BorderBrush" Value="DarkGray"></Setter>
<Setter Property="Foreground" Value="DarkGray"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</iconPacks:PackIconModern.Style>
</iconPacks:PackIconModern>
</Button>
</StackPanel>
</Grid>
</Controls:Tile>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>