WPFとC#で、コントロールとそのバインディングがコードビハインドで実行時に作成されるWPFアプリケーションで作業しています。 コントロールを使用するWPFウィンドウには、DataTableをDataContextとして持つViewModelがあり、下部にはDataTableのDefaultViewにバインドされたDataGridがあります。WPFのCustomControlsでUpdateSourceTriggerが動作しません
まず、実行時にコントロールを作成するために、私は標準のWPFコントロールを使用しました。 TextBoxとCheckBoxを使用します。 は彼らのバインディングでは、私はこのように「のPropertyChanged」UpdateSourceTriggerを設定します。私は(それを残さずに)テキストボックスのテキストを変更またはチェック
Binding controlBinding = new Binding();
controlBinding.Source = ViewModelContainer.viewmodel.ApplicationDataSet.Tables[BindingSource].DefaultView;
controlBinding.Path = new PropertyPath("[0][" + BindingPath + "]");
controlBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
/私は、データグリッドにすべてを一度にこれらの変化を見たCheckBoxのチェックを外します。
今は標準コントロールから継承したCustomControlsを使用していますが、UpdateSourceTrigger機能はもう機能しません。 TextBoxのテキストを変更したり、CheckBoxのチェックを外したりすると、DataGridに変更はありません。
私は自分のCustomControlsの定義で何かをしなければならないと思いますが、何ですか?ここで
CustomTextBoxとCustomCheckBoxの定義:
<!--Style for the CustomControl CustomTextBox-->
<Style TargetType="{x:Type local:CustomTextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomTextBox}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TextBox Text="{TemplateBinding Text}"
TextWrapping="Wrap"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ContextMenu="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:CustomTextBox}},
Path=ContextMenu}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--Style for the CustomControl CustomCheckBox-->
<Style TargetType="{x:Type local:CustomCheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomCheckBox}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<CheckBox IsChecked="{TemplateBinding IsChecked}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
<TextBlock Text="{TemplateBinding Text}"
TextWrapping="Wrap"
TextAlignment="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type CheckBox}},
Path=HorizontalContentAlignment, Converter={StaticResource h2tAlignmentConverter}}"
TextDecorations="{TemplateBinding TextDecorations}"/>
</CheckBox>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
事前に感謝!