首页 > 解决方案 > WPF 绑定未引发数据模板类型扩展器的属性更改事件

问题描述

绑定到视图模型的 xaml 属性仅在加载 UI 后获取值,在任何更改时,不会引发 Raise 属性更改事件并且不会使用最新值更新。

我还有一个 xaml,其中相同的实现按预期工作,但唯一的区别是此 xaml 包含数据模板,因为此视图模型中的所有属性都不会触发 Raise property changed 事件并在任何更改时更新 UI。

这是我在视图模型中的属性

 public bool IsDataValid
    {
        get        
        {return isDattaValid;}
        set
        {        
            isDattaValid = value;
            RaisePropertyChangedEvent("IsDataValid");
        }
    }

这是我的 xaml

 <Expander Grid.Row="6" x:Name="AdvanceSettingsExpander">
        <Expander.Resources>
            <DataTemplate x:Key="serviceTemplateKey">
                <StackPanel Orientation="Horizontal">                    
                    <TextBlock Margin="0,0,6,0" Foreground="Red" Text= "!"                                
                               Visibility="{Binding IsDataValid, Converter={StaticResource BoolToVisibilityConv},  Mode=TwoWay, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"/>
                    <TextBlock Margin="0,0,6,0" Text="Advance Settings for "></TextBlock>
                    <TextBlock Margin="0,0,6,0" Text=":"></TextBlock>
                    <TextBlock  Margin="0,0,6,0" 
                       Text="{Binding Path=Name}" Width="Auto"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </Expander.Resources>
        <Expander.Header>
            <ContentControl  Content="{Binding Path=ConfiguredServices}" 
                         ContentTemplate="{StaticResource serviceTemplateKey}">                   
            </ContentControl>
        </Expander.Header> 
        <ContentControl
            Content="{Binding Path=RemDevAdvanceSettingHostingContent}"
            IsEnabled="{Binding Path=IsAdvConfigAllowed}"            
            Margin="4,0,0,0" Height="Auto"/>
    </Expander>

标签: wpfxamldata-bindingdatatemplateinotifypropertychanged

解决方案


推荐阅读