绑定延迟 属性 WPF - 我没有注意到任何区别

Binding Delay property WPF - I didn't notice any difference

我试图了解更多关于绑定延迟及其影响的信息。我已经实现了一个简单的代码,但老实说,无论有没有延迟,我最终都没有注意到任何视觉差异。这是代码:

<Window x:Class="Example00.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Window1" Height="300" Width="300">

<Grid  >   
    <Grid.RowDefinitions >
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBox Name="mySourceElement" Grid.Row="0" >Hello World</TextBox>
    <TextBlock Grid.Row="1">            
        <TextBlock.Text>
            <Binding ElementName="mySourceElement" Path="Text" Mode="TwoWay" Delay="60000" />
        </TextBlock.Text>
    </TextBlock> 

    <TextBlock Text="{Binding ElementName=mySourceElement, Mode=TwoWay, Path=Text, Delay=50000}" Grid.Row="2" />
</Grid>

它基本上是基于代码项目教程的代码(http://www.codeproject.com/Articles/29054/WPF-Data-Binding-Part - 示例零),但使用 .Net 4.5 并添加了延迟。我添加了一个很长的延迟以直观地看到差异,但是我没有注意到与不使用延迟有什么不同。

我想知道我是否误解了 属性 - 其他文本框上的文本不应该等待 "delay" 数量来反映用户在第一个文本框上键入的更改吗?

是的,您有点误解了 Delay。这个 属性 的命名方式非常混乱。事实上,它只有一种方式,从目标到源。这意味着当目标发生每次更改时,更新到源的更改将被延迟。另一种方法行不通,这意味着源中发生的每个更改都不会延迟对目标的反映。

所以在这种情况下应该是这样的:

<!-- NOTE: we name TextBlock as target but 
     in fact it's the source of the Binding -->
<TextBox Text="{Binding Text, ElementName=target, Mode=TwoWay, 
                UpdateSourceTrigger=PropertyChanged, Delay=1000}"
         ></TextBox>
<TextBlock Grid.Row="1" Name="target">            
</TextBlock> 

在您的代码中,您的 Binding 的来源为 TextBox,目标为 TextBlock。因此 TextBox 中的每个更改都会立即反映到 TextBlock 而不受 Delay.

的影响