1

私はユーザーコントロールを持っていますが、ウィンドウにそれがたくさんあると、ロードされるのに長い時間がかかります。DataTemplateカスタムコントロールに変更したり、クラスとアタッチされたプロパティを持つに変更したりすると、さらに良くなりますか?どんなアイデアでも大歓迎です。

編集:

これが私のコントロールです:

<UserControl 
    x:Class="Pouyansoft.WPF.MVVM.Control.Common.View.DataGridSelectorControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    x:Name="dataGridSelector"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d" >
<UserControl.Resources>
    <CollectionViewSource Source="{Binding DataCollection.Source}" x:Key="theSource"/>
    <Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="{TemplateBinding Content}" 
                                   HorizontalAlignment="Center" />
                        <TextBox x:Name="txtSearch" Grid.Row="1"  HorizontalAlignment="Stretch"  
                                 BorderThickness="1" TextChanged="TextBox_TextChanged" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<Grid>       
   <DataGrid x:Name="grd" 
             ItemsSource="{Binding Source={StaticResource theSource}}" 
             AutoGenerateColumns="False"
             ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"   
             PreviewKeyDown="grd_PreviewKeyDown"
             SelectedIndex="{Binding SelectedIndex}"
             behavior:MouseDoubleClick.Command="{Binding MouseDoubleClickCommand}" 
             PreviewMouseLeftButtonUp="grid1_PreviewMouseLeftButtonUp"  
             GridLinesVisibility="Vertical">
    </DataGrid>
</Grid>

コードビハインドの一部のコード(実際には、他のすべてのコントロールは同じ動作をします)

4

1 に答える 1

1

まず、使用しないでDynamicResourceくださいStaticResource-

使用する

ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle1}"

代わりに

ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"

次に、出力ウィンドウでバインディング エラーをチェックし、できるだけ多くのエラーを修正してみてください。

また、使用する利点はありませんCollectionViewSource(並べ替え、フィルタリング、グループ化を行っていないため)。を使用する必要がない場合はCollectionViewSource、 を に直接バインドできDataGridます。ItemSourceDataCollection.Source

于 2012-06-11T07:08:56.087 に答える