我正在创建一个用于体育赛事管理的应用程序,我想绘制一个这样的锦标赛支架:
<ItemsControl ItemsSource="{Binding PlayOff.Series}" Name="roundSource">
<ItemsControl.ItemsPanel>
<itemspaneltemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
</itemspaneltemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding}" Name="matchSource">
<ItemsControl.ItemsPanel>
<itemspaneltemplate>
<UniformGrid Columns="1"/>
</itemspaneltemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,20">
<Grid Margin="0,-20">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Border Grid.Row="1" Grid.RowSpan="2" BorderBrush="Black" BorderThickness="3" Width="3"/>
</Grid>
<Border BorderBrush="Black" BorderThickness="3" Width="200" Height="3"/>
<Grid>
<StackPanel Orientation="Horizontal">
<TextBox IsReadOnly="True" Padding="5,2" Width="180" Text="{Binding FirstTeam.Name}"/>
<Button Content="X" Width="40" Command="{Binding Path=DataContext.RemoveTeamFromSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<ComboBox Width="180" ItemsSource="{Binding Path=DataContext.NotSelectedTeams,ElementName=roundSource}" DisplayMemberPath="Name" IsEditable="True"/>
<Button Width="40" Content="+" Command="{Binding Path=DataContext.AddFirstTeamToSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
</Grid>
<Border BorderBrush="Black" BorderThickness="3" Width="200" Height="3"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
第一个 itemsource 获取有关括号轮次的数据,然后第二个 itemsource 获取有关该轮次匹配的数据。 但是,当括号更大时,例如 8 轮(仅第一轮有 128 场比赛),渲染它需要几秒钟(应用程序冻结)。
如何提高性能? 我尝试使用位图缓存和缓存模式缓存控件,但它不起作用,我尝试了不同的控件,但也许我只是不知道应该如何正确完成。你能帮我吗?
更新:
我被要求提供更多代码。
<Border HorizontalAlignment="Center" BorderBrush="Black" BorderThickness="1">
<Viewbox StretchDirection="DownOnly" Stretch="UniformToFill" MaxHeight="600">
<zoomborder:zoomBorder x:Name="border" ClipToBounds="True" Background="LightSteelBlue">
<ItemsControl ItemsSource="{Binding PlayOff.Series}" Name="roundSource">
<ItemsControl.ItemsPanel>
<itemspaneltemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
</itemspaneltemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding}" Name="matchSource">
<ItemsControl.ItemsPanel>
<itemspaneltemplate>
<UniformGrid Columns="1"/>
</itemspaneltemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,20">
<Grid Visibility="{Binding PreLineVisibility}" Margin="0,-20">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Border Grid.Row="1" Grid.RowSpan="2" BorderBrush="Black" BorderThickness="3" Width="3"/>
</Grid>
<Border Visibility="{Binding PreLineVisibility}" BorderBrush="Black" BorderThickness="3" Width="200" Height="3"/>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Grid IsEnabled="{Binding FirstIsEnabled}">
<StackPanel Visibility="{Binding FirstSelectedVisibility}" Orientation="Horizontal">
<TextBox IsReadOnly="True" Padding="5,2" Width="180" TextWrapping="Wrap" Text="{Binding FirstTeam.Name}"/>
<Button Content="X" Width="40" FontWeight="Bold" Command="{Binding Path=DataContext.RemoveFirstTeamFromSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
<StackPanel Visibility="{Binding FirstNotSelectedVisibility}" Orientation="Horizontal">
<ComboBox Width="180" ItemsSource="{Binding Path=DataContext.NotSelectedTeams,ElementName=roundSource}" SelectedItem="{Binding FirstSelectedTeam}" DisplayMemberPath="Name" IsEditable="True"/>
<Button Width="40" Content="+" FontWeight="Bold" Command="{Binding Path=DataContext.AddFirstTeamToSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
</Grid>
<Grid IsEnabled="{Binding SecondIsEnabled}">
<StackPanel Visibility="{Binding SecondSelectedVisibility}" Orientation="Horizontal">
<TextBox IsReadOnly="True" Padding="5,2" Width="180" TextWrapping="Wrap" Text="{Binding SecondTeam.Name}"/>
<Button Content="X" Width="40" FontWeight="Bold" Command="{Binding Path=DataContext.RemoveSecondTeamFromSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
<StackPanel Visibility="{Binding SecondNotSelectedVisibility}" Orientation="Horizontal">
<ComboBox Width="180" ItemsSource="{Binding Path=DataContext.NotSelectedTeams,ElementName=roundSource}" SelectedItem="{Binding SecondSelectedTeam}" DisplayMemberPath="Name" IsEditable="True"/>
<Button Width="40" Content="+" FontWeight="Bold" Command="{Binding Path=DataContext.AddSecondTeamToSerieCommand,ElementName=roundSource}" commandparameter="{Binding}"/>
</StackPanel>
</Grid>
</StackPanel>
<Border Visibility="{Binding PostLineVisibility}" BorderBrush="Black" BorderThickness="3" Width="200" Height="3"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</zoomborder:zoomBorder>
</Viewbox>
</Border>