C# c代码中的wpf Mahapps磁贴或带有数据绑定和自定义数据模板
我尝试在Scrollviewer中动态构建分幅。所有数据都来自Web服务中填写的列表 DataTemplate应该是一个有两个标签和一张图片的网格,我现在尝试了不同的方法,但看起来我还不了解一些基础知识。有人能帮我举个例子吗 ScrollViewer是一个内容控件。要显示项目列表(如平铺),需要使用项目控件(如ListView或ItemsControl)的ItemsSource属性C# c代码中的wpf Mahapps磁贴或带有数据绑定和自定义数据模板,c#,wpf,C#,Wpf,我尝试在Scrollviewer中动态构建分幅。所有数据都来自Web服务中填写的列表 DataTemplate应该是一个有两个标签和一张图片的网格,我现在尝试了不同的方法,但看起来我还不了解一些基础知识。有人能帮我举个例子吗 ScrollViewer是一个内容控件。要显示项目列表(如平铺),需要使用项目控件(如ListView或ItemsControl)的ItemsSource属性 换句话说,您需要使用{Binding…}语法将列表绑定到ListView的ItemsSource,并确保设置了视图
换句话说,您需要使用{Binding…}语法将列表绑定到ListView的ItemsSource,并确保设置了视图的DataContext,并且列表是DataContext类的一部分,通常是ViewModel。仅供参考,感谢您的提示/帮助。以下是解决方案。我希望它是正确的,可以提供它
<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>