うまくいけば、これは経験豊富なWPFユーザーにとって明らかです。バインドするとき、バインドしているターゲットの(埋め込まれた)レベルを考慮する必要がありますか?
以下のXAMLには、独自の追加のvalidationRulesのリストを受け入れることができるMyTextBoxがあります。FileNameValidationRuleには、InputPathStr文字列依存関係プロパティを持つPathStr型のValidPathStrがあります。
私の理論をテストするために、MyTextBoxのテキストのバインディングをMyTextBoxのInputPathStrと同じバインディングに設定してみました。テキストのバインディングは機能しているように見えましたが(正しくはありませんが、それでもバインディングを解決しようとしました)、InputPathStrへのバインディングで「フレームワークメンターが見つかりません」というエラーが発生しました。以下のトレースは出力を示しています。最初のチャンクはTextバインディングで、2番目のチャンクは失敗したInputPathStrバインディングです。
両方のバインディングが機能するか、両方が失敗することを期待していましたが、InputPathStrのバインディングを変更して、Textの場合と同じように機能させるにはどうすればよいですか?
ありがとう。
<my2:MyTextBox x:Name="m_renameTextBox"
Text="{Binding Path=SourceBrowseDir.ItemFullPath, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" >
<my2:MyTextBox.AdditionalValidationRules>
<src:FileNameValidationRule>
<src:FileNameValidationRule.ValidPathStr>
<src:PathStr InputPathStr="{Binding Path=SourceBrowseDir.ItemFullPath, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</src:FileNameValidationRule.ValidPathStr>
</src:FileNameValidationRule>
</my2:MyTextBox.AdditionalValidationRules>
</my2:MyTextBox >
出力は次のとおりです。
> Created BindingExpression (hash=3780752) for Binding (hash=63892678)
Path: 'SourceBrowseDir.ItemFullPath'
BindingExpression (hash=3780752): Attach to ScreenControls.HelperUserControls.MyTextBox.Text (hash=20793123)
BindingExpression (hash=3780752): Resolving source
BindingExpression (hash=3780752): Found data context element: MyTextBox (hash=20793123) (OK)
BindingExpression (hash=3780752): Activate with root item PresetsNavigatorViewModel (hash=34365244)
BindingExpression (hash=3780752): At level 0 using cached accessor for PresetsNavigatorViewModel.SourceBrowseDir: RuntimePropertyInfo(SourceBrowseDir)
BindingExpression (hash=3780752): Replace item at level 0 with PresetsNavigatorViewModel (hash=34365244), using accessor RuntimePropertyInfo(SourceBrowseDir)
BindingExpression (hash=3780752): GetValue at level 0 from PresetsNavigatorViewModel (hash=34365244) using RuntimePropertyInfo(SourceBrowseDir): <null>
BindingExpression (hash=3780752): Item at level 1 is null - no accessor
BindingExpression (hash=3780752): TransferValue - got raw value {DependencyProperty.UnsetValue}
BindingExpression (hash=3780752): TransferValue - using fallback/default value ''
BindingExpression (hash=3780752): TransferValue - using final value ''
>
> Created BindingExpression (hash=56631954) for Binding (hash=47211710)
Path: 'SourceBrowseDir.ItemFullPath'
BindingExpression (hash=56631954): Attach to ScreenControls.Helper.PathStr.InputPathStr (hash=40208759)
BindingExpression (hash=56631954): Use Framework mentor <null>
BindingExpression (hash=56631954): Resolving source
BindingExpression (hash=56631954): Framework mentor not found
BindingExpression (hash=56631954): Resolve source deferred