0

simpleChartという名前のユーザーコントロールをDataGridTemplateColumnに入れようとしています。DataGridをにバインドしますObservableCollection<Index>(ここで、Indexは表示用に作成したINotifyPropertyChangedクラスです)。しかし、どういうわけか、バインディングはルートアイテムを見つけることができません。バインディングを確認するために、templateColumnの横にtextColumnを配置しましたが、問題なく機能します。関連するコードは次のとおりです。

<Window x:Class="TechniqueAnalysis.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="549" Width="1744" 
    xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    xmlns:local="clr-namespace:Charts"
    xmlns:simpleChart ="clr-namespace:ChartOnGird;assembly=ChartOnGird"
    WindowState="Maximized" Closing="Window_Closing">
<Grid>
<DataGrid Margin="0,60,0,0" Name="dataGridWei" CanUserResizeColumns="False"  ItemsSource="{Binding}">
<DataGridTemplateColumn Header="2 day"  Width="100">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
           <simpleChart:SimpleChart X ="{Binding Path=X1, diagnostics:PresentationTraceSources.TraceLevel=High}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Value" Binding="{Binding Path=X1, diagnostics:PresentationTraceSources.TraceLevel=High, StringFormat=N2}"/>
</DataGrid>
</Grid>
</Window>

データバインディングは、ObservableCollectionをデータグリッドのDataContextにバインドするバックグラウンドコードを介して行われます。

そして、テンプレート列に対して次の出力が得られます。

System.Windows.Data Warning: 58 : BindingExpression (hash=45649854): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=45649854): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=45649854): Attach to ChartOnGird.SimpleChart.X (hash=40977533)
System.Windows.Data Warning: 65 : BindingExpression (hash=45649854): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=45649854): Found data context element: SimpleChart (hash=40977533) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=45649854): Activate with root item ''
System.Windows.Data Warning: 106 : BindingExpression (hash=45649854):   At level 0 - for String.X1 found accessor <null>
System.Windows.Data Warning: 106 : BindingExpression (hash=45649854):   At level 0 - for EnumerableCollectionView.X1 found accessor <null>
System.Windows.Data Warning: 102 : BindingExpression (hash=45649854): Replace item at level 0 with {NullDataItem}, using accessor {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 78 : BindingExpression (hash=45649854): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=45649854): TransferValue - using fallback/default value '9'
System.Windows.Data Warning: 87 : BindingExpression (hash=45649854): TransferValue - using final value '9'
System.Windows.Data Warning: 54 : Created BindingExpression (hash=32948864) for Binding (hash=33575416)

しかし、テキスト列については、次の警告が表示されます。

System.Windows.Data Warning: 58 : BindingExpression (hash=32948864): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=32948864): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=32948864): Attach to System.Windows.Controls.TextBlock.Text (hash=6303902)
System.Windows.Data Warning: 65 : BindingExpression (hash=32948864): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=32948864): Found data context element: TextBlock (hash=6303902) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=32948864): DataContext is null
System.Windows.Data Warning: 63 : BindingExpression (hash=32948864): Resolve source deferred
System.Windows.Data Warning: 65 : BindingExpression (hash=8194399): Resolving source 
System.Windows.Data Warning: 68 : BindingExpression (hash=8194399): Found data context element: TextBlock (hash=33203677) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=8194399): Activate with root item Index (hash=33903126)
System.Windows.Data Warning: 106 : BindingExpression (hash=8194399):   At level 0 - for Index.X1 found accessor RuntimePropertyInfo(X1)
System.Windows.Data Warning: 102 : BindingExpression (hash=8194399): Replace item at level 0 with Index (hash=33903126), using accessor RuntimePropertyInfo(X1)
System.Windows.Data Warning: 99 : BindingExpression (hash=8194399): GetValue at level 0 from Index (hash=33903126) using RuntimePropertyInfo(X1): '1'
System.Windows.Data Warning: 78 : BindingExpression (hash=8194399): TransferValue - got raw value '1'
System.Windows.Data Warning: 82 : BindingExpression (hash=8194399): TransferValue - implicit converter produced '1.00'
System.Windows.Data Warning: 87 : BindingExpression (hash=8194399): TransferValue - using final value '1.00'
System.Windows.Data Warning: 65 : BindingExpression (hash=32948864): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=32948864): Found data context element: TextBlock (hash=6303902) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=32948864): Activate with root item Index (hash=49245678)
System.Windows.Data Warning: 105 : BindingExpression (hash=32948864):   At level 0 using cached accessor for Index.X1: RuntimePropertyInfo(X1)
System.Windows.Data Warning: 102 : BindingExpression (hash=32948864): Replace item at level 0 with Index (hash=49245678), using accessor RuntimePropertyInfo(X1)
System.Windows.Data Warning: 99 : BindingExpression (hash=32948864): GetValue at level 0 from Index (hash=49245678) using RuntimePropertyInfo(X1): '1'
System.Windows.Data Warning: 78 : BindingExpression (hash=32948864): TransferValue - got raw value '1'
System.Windows.Data Warning: 82 : BindingExpression (hash=32948864): TransferValue - implicit converter produced '1.00'
System.Windows.Data Warning: 87 : BindingExpression (hash=32948864): TransferValue - using final value '1.00'

templatecolumnが正しいルートアイテムを見つけられないようです。問題は、適切なものを見つけるのに役立つ適切な方法は何ですか?RelateSourceを追加しようとしましたが、その方法がわかりませんでした。私のクラス「Index」はMainWindowクラスの下にあります。私を助けてください。私はそれに2日を費やしました。私はもうすぐそこにいると思いますが、助けなしでは理解できないことがあります。

4

1 に答える 1

0

問題はあなたのsimpleChartだと思いますUserControl。おそらくDataContext、このコントロールのを間違った方法で設定したため、バインディングはではRow.DataContextなく、を検出しUserControl.DataContextます。

再利用可能なUserControlを作成するためのこの単純なパターンを見て、正しい方法で実行してください。

于 2012-07-03T22:20:13.363 に答える