えムナウ Blog

えムナウ の なすがまま

目次

Blog 利用状況

ニュース


follow mnow at http://twitter.com


えムナウのプログラミングのページ

INETAJ

書庫

日記カテゴリ

ギャラリ

WPF データーバインディング CoerceValueCallback 問題かも

そんなわけはありません。

と言ってみたけど検証不足でした。

そうかも。

前回は TextBox や Label から Slider への Binding でした。
でも実際使うとしたら Slider から データへの Binding です。

<Window x:Class="BindingTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="300" Width="300">
    <Grid>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Slider  Name="slider1" Value="{Binding ElementName=textBox2,Path=Text,diag:PresentationTraceSources.TraceLevel=High}"/>
    <TextBox Grid.Row="1" Name="textBox1" Text="{Binding ElementName=slider1,Path=Value,Mode=TwoWay,diag:PresentationTraceSources.TraceLevel=High}" />
    <Label Grid.Row="2" Name="label1" Content="{Binding ElementName=slider1,Path=Value,diag:PresentationTraceSources.TraceLevel=High}"/>
    <Button Grid.Row="3" Name="button1" Click="button1_Click">Button</Button>
    <TextBox Grid.Row="4" Name="textBox2"/>
  </Grid>
</Window>

slider1 から textBox2 に Binding させてみました。

1)依存関係プロパティーの値を変更 ボタンをクリックすれば slider1.Value =  - 10 となる
System.Windows.Data Warning: 86 : BindingExpression (hash=41014879): Update - got raw value '-10'
System.Windows.Data Warning: 89 : BindingExpression (hash=41014879): Update - implicit converter produced '-10'
System.Windows.Data Warning: 90 : BindingExpression (hash=41014879): Update - using final value '-10'
System.Windows.Data Warning: 98 : BindingExpression (hash=41014879): SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '-10'
System.Windows.Data Warning: 92 : BindingExpression (hash=32176063): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=32176063): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=32176063): TransferValue - got raw value '0'
System.Windows.Data Warning: 80 : BindingExpression (hash=32176063): TransferValue - implicit converter produced '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=32176063): TransferValue - using final value '0'
System.Windows.Data Warning: 92 : BindingExpression (hash=24123405): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=24123405): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '0'
System.Windows.Data Warning: 76 : BindingExpression (hash=24123405): TransferValue - got raw value '0'
System.Windows.Data Warning: 85 : BindingExpression (hash=24123405): TransferValue - using final value '0'

SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '-10' TextBox に ? 10 をセットしています。


2)プロパティーの値を変える TextBox の値を 20 に変更すれば Mode=TwoWay で Slider.Value を変更する
System.Windows.Data Warning: 91 : BindingExpression (hash=32176063): Got LostFocus event from TextBox (hash=44150175)
System.Windows.Data Warning: 86 : BindingExpression (hash=32176063): Update - got raw value '20'
System.Windows.Data Warning: 89 : BindingExpression (hash=32176063): Update - implicit converter produced '20'
System.Windows.Data Warning: 90 : BindingExpression (hash=32176063): Update - using final value '20'
System.Windows.Data Warning: 98 : BindingExpression (hash=32176063): SetValue at level 0 to Slider (hash=3888474) using DependencyProperty(Value): '20'
System.Windows.Data Warning: 86 : BindingExpression (hash=41014879): Update - got raw value '20'
System.Windows.Data Warning: 89 : BindingExpression (hash=41014879): Update - implicit converter produced '20'
System.Windows.Data Warning: 90 : BindingExpression (hash=41014879): Update - using final value '20'
System.Windows.Data Warning: 98 : BindingExpression (hash=41014879): SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '20'
System.Windows.Data Warning: 92 : BindingExpression (hash=32176063): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=32176063): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=32176063): TransferValue - got raw value '10'
System.Windows.Data Warning: 80 : BindingExpression (hash=32176063): TransferValue - implicit converter produced '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=32176063): TransferValue - using final value '10'
System.Windows.Data Warning: 92 : BindingExpression (hash=24123405): Got PropertyChanged event from Slider (hash=3888474) for Value
System.Windows.Data Warning: 97 : BindingExpression (hash=24123405): GetValue at level 0 from Slider (hash=3888474) using DependencyProperty(Value): '10'
System.Windows.Data Warning: 76 : BindingExpression (hash=24123405): TransferValue - got raw value '10'
System.Windows.Data Warning: 85 : BindingExpression (hash=24123405): TransferValue - using final value '10'

SetValue at level 0 to TextBox (hash=34340385) using DependencyProperty(Text): '20' TextBox にやっぱり 20 を入れています。

しかし、問題点として、Slider の CoerceValueCallback のロジックと、textBox2(データソース側)の CoerceValueCallback のロジックが矛盾していたら困るので解決方法はないかも。

データソース側に CoerceValueCallback は通常つけないだろう(DependencyPropertyじゃないのが普通だし)がWPFの場合は両方ともコントロールの場合があるので起こりえるんです。

投稿日時 : 2009年6月2日 22:42

コメントを追加

# My spouse and I stumbled over here from a different web address and thought I might as well check things out. I like what I see so i am just following you. Look forward to exploring your web page repeatedly. 2019/04/05 8:59 My spouse and I stumbled over here from a differe

My spouse and I stumbled over here from a different web address and thought I might
as well check things out. I like what I see so i
am just following you. Look forward to exploring your web page repeatedly.

# Hello there! I could have sworn I've been to this website before but after reading through some of the post I realized it's new to me. Anyways, I'm definitely happy I found it and I'll be bookmarking and checking back frequently! 2019/04/09 21:20 Hello there! I could have sworn I've been to this

Hello there! I could have sworn I've been to this
website before but after reading through some of the post I realized
it's new to me. Anyways, I'm definitely happy I found it and I'll be bookmarking and checking back frequently!

# Hmm is anyone else having problems with the images on this blog loading? I'm trying to determine if its a problem on my end or if it's the blog. Any feed-back would be greatly appreciated. 2019/05/01 19:51 Hmm is anyone else having problems with the images

Hmm is anyone else having problems with the
images on this blog loading? I'm trying to determine
if its a problem on my end or if it's the blog.
Any feed-back would be greatly appreciated.

# Hey! Someone in my Facebook group shared this site with us so I came to give it a look. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Outstanding blog and wonderful design. 2019/06/15 14:02 Hey! Someone in my Facebook group shared this site

Hey! Someone in my Facebook group shared this site with us so I came to give it a look.

I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers!
Outstanding blog and wonderful design.

# KZCSdERmBCaY 2021/07/03 4:58 https://www.blogger.com/profile/060647091882378654

This is one awesome article post. Fantastic.

# Illikebuisse paany 2021/07/03 9:42 pharmacepticacom

sildenafil generic 100 mg https://www.pharmaceptica.com/

# erectile disorder psychology 2021/07/06 10:17 hydroxychlor 200mg

plaquenil sulfate 200 mg https://plaquenilx.com/# hydroxychloroquone

# re: WPF ??????????? CoerceValueCallback ???? 2021/07/10 9:50 hydroxychloride 200 mg

chloroquine tablet https://chloroquineorigin.com/# risks of hydroxychloroquine

# re: WPF ??????????? CoerceValueCallback ???? 2021/07/16 14:11 what is hydroxychloroquine sulfate

chloronique https://chloroquineorigin.com/# quinine for lupus

# re: WPF ??????????? CoerceValueCallback ???? 2021/07/26 3:35 hydroxychloroquine side effect

chloroquine amazon https://chloroquineorigin.com/# dosage for hydroxychloroquine

# gdmoqlvzivfj 2022/05/20 14:12 zbrcxmay

how to use erythromycin ophthalmic ointment https://erythromycin1m.com/#

# Test, just a test 2022/12/15 22:56 candipharm com

canadian customs pills vitamins http://candipharm.com/#

タイトル
名前
URL
コメント