Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 如何在列表框中的DataTemplate中获取TextBox,以便在值更改时通知ViewModel_Silverlight_Xaml_Viewmodel_Mvvm - Fatal编程技术网

Silverlight 如何在列表框中的DataTemplate中获取TextBox,以便在值更改时通知ViewModel

Silverlight 如何在列表框中的DataTemplate中获取TextBox,以便在值更改时通知ViewModel,silverlight,xaml,viewmodel,mvvm,Silverlight,Xaml,Viewmodel,Mvvm,我需要找到的是,当文本框的值发生变化或我的datatemplate项中的下拉列表的值发生变化时,我需要在我的ViewModel.cs中得到通知 因此,基本上,当用户编辑listbox中的文本框时,viewmodel将在值更改时收到通知 原因是我需要检查所有条目,并在列表框的datatemplate中的项发生更改时更新某些内容 有什么建议吗 我的XAML中有以下内容 <ListBox x:Name="EntriesListBox" ItemsSource="{Binding

我需要找到的是,当文本框的值发生变化或我的datatemplate项中的下拉列表的值发生变化时,我需要在我的ViewModel.cs中得到通知

因此,基本上,当用户编辑listbox中的文本框时,viewmodel将在值更改时收到通知

原因是我需要检查所有条目,并在列表框的datatemplate中的项发生更改时更新某些内容

有什么建议吗

我的XAML中有以下内容

<ListBox x:Name="EntriesListBox"
         ItemsSource="{Binding Path=Entries}"
         Grid.Row="1">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <ComboBox x:Name="EntriesPropertyName"
                          Width="215"
                          Margin="0,0,5,0"
                          SelectedItem="{Binding Path=Property, Mode=TwoWay}"
                          ItemsSource="{Binding Source={StaticResource DataContextProxy},Path=DataSource.EntityTypeProperties}" />               
                <TextBox x:Name="EntriesPropertyValue"
                         Width="215"
                         Margin="0,0,5,0"
                         Text="{Binding Path=Value, Mode=TwoWay, BindsDirectlyToSource=True}" />                                   
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

在绑定时,设置。。。同时在绑定上实现

,设置。。。如果已正确设置视图模型类(通过实现INotifyPropertyChanged),还可以实现以下操作:

 <TextBox x:Name="EntriesPropertyValue"
                         Width="215"
                         Margin="0,0,5,0"
                         Text="{Binding Path=Value, Mode=TwoWay, BindsDirectlyToSource=True, UpdateSourceTrigger=PropertyChanged}" /> 

如果已正确设置视图模型类(通过实现INotifyPropertyChanged),则可能需要执行以下操作:

 <TextBox x:Name="EntriesPropertyValue"
                         Width="215"
                         Margin="0,0,5,0"
                         Text="{Binding Path=Value, Mode=TwoWay, BindsDirectlyToSource=True, UpdateSourceTrigger=PropertyChanged}" /> 

这似乎有效。有什么理由不这样做吗

private void EntriesPropertyValue_TextChanged(object sender, TextChangedEventArgs e)
{
    (sender as TextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource();

    this.ViewModel.UpdateFinalQuery();
}

这似乎奏效了。有什么理由不这样做吗

private void EntriesPropertyValue_TextChanged(object sender, TextChangedEventArgs e)
{
    (sender as TextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource();

    this.ViewModel.UpdateFinalQuery();
}

我在Silverlight 4工作;silverlight中没有UpdateSourceTrigger=PropertyChanged,请确保模式设置为双向!此外,他们的一些行为,你可以添加,黑客它。。。它会侦听按键关闭事件,然后强制更新!我在Silverlight 4工作;silverlight中没有UpdateSourceTrigger=PropertyChanged,请确保模式设置为双向!此外,他们的一些行为,你可以添加,黑客它。。。它会侦听按键关闭事件,然后强制更新!