3 つの可能なデータ テンプレートを持つitemcontrolがあります。
<DataTemplate>
<StackPanel>
<TextBlock
FontSize="25"
FontWeight="Light"
Margin="0,8,0,5"
Text="{Binding Name}" >
</TextBlock>
<!-- Εδω τα items -->
<ContentControl
Content="{Binding Preferences}"
Name="items" >
</ContentControl>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger
Binding="{Binding Path=SelectionMode}"
Value="1" >
<Setter
Property="ContentTemplate"
TargetName="items"
Value="{StaticResource SoloSelection}" />
</DataTrigger>
<DataTrigger
Binding="{Binding Path=SelectionMode}"
Value="2" >
<Setter
Property="ContentTemplate"
TargetName="items"
Value="{StaticResource MultiSelection}" />
</DataTrigger>
<DataTrigger
Binding="{Binding Path=SelectionMode}"
Value="3" >
<Setter
Property="ContentTemplate"
TargetName="items"
Value="{StaticResource MultiQuantitySelection}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
中のものはいくつかのボタンが付いているラップパネルです. したがって、仮想化はそれほど簡単ではないようです.そして、スムーズなスクロールが必要です. 問題は、ボタンはボーダーとテキストブロックですが、遅いことです。
私はテストをしました。
var sw = new Stopwatch();
sw.Start();
var vv = new SolidColorBrush(Colors.Red);
for (int i = 0; i < 150; i++)
{
// here is the operation that fills the control
var b = new Button();
b.Height = 65;
b.Width = 120;
b.Content = "Gamiese";
this.items.Items.Add(b);
}
this.Dispatcher.BeginInvoke(
DispatcherPriority.Loaded,
new Action(() =>
{
sw.Stop();
MessageBox.Show("Took " + sw.ElapsedMilliseconds + " ms");
}));
}
これには、私のコンピューターでは約 40 ~ 50 ミリ秒かかりますが、遅いコンピューターでは 200 ミリ秒以上かかります。したがって、この単純な例ではなく、他のすべてのものを使用すると、600〜900ミリ秒になる可能性があります。そのため、タッチ エクスペリエンスは遅く、痛みを伴う場合があります。QT QMLで同様のテストを行い、200個の重いボタンを作成して瞬時に点灯し、スムーズにスクロールしたため、これはWPFのせいです。そのため、WPF はそのままではうまく機能しません。何か私にできることはありますか ?ボタンをキャッシュしても役に立ちません。ツリーにデータを入力するのが問題のようです。すべてのコンピューターでスクロールが非常に高速であるため、レンダリングは問題ではありません。