Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
C# 页面内控件的错误模板未显示_C#_Wpf_Errortemplate - Fatal编程技术网

C# 页面内控件的错误模板未显示

C# 页面内控件的错误模板未显示,c#,wpf,errortemplate,C#,Wpf,Errortemplate,我在一个页面中有一个文本框,它绑定到一个已验证的模型属性,当出现错误时,错误模板不会显示 有几点: 我对自己窗口中的控件没有验证问题(不在窗口框架中显示的页面中) 错误模板起作用,它在窗口中为控件显示 该模型正在验证,因为在识别验证错误时,页面中的“保存”按钮被禁用 我“认为”问题在于,控件位于框架内托管的页面内,因此数据上下文不会传递给页面,因为它看起来是孤立的。是这样吗?如果是这样,我该如何着手解决这个问题?如果不是,那还会是什么呢 代码(我当然简化了代码以隔离问题): 如果我可以添加

我在一个页面中有一个文本框,它绑定到一个已验证的模型属性,当出现错误时,错误模板不会显示

有几点:

  • 我对自己窗口中的控件没有验证问题(不在窗口框架中显示的页面中)
  • 错误模板起作用,它在窗口中为控件显示
  • 该模型正在验证,因为在识别验证错误时,页面中的“保存”按钮被禁用
  • 我“认为”问题在于,控件位于框架内托管的页面内,因此数据上下文不会传递给页面,因为它看起来是孤立的。是这样吗?如果是这样,我该如何着手解决这个问题?如果不是,那还会是什么呢

    代码(我当然简化了代码以隔离问题):

    
    


    如果我可以添加任何进一步的信息或代码,请让我知道

    问题已解决-据了解,Windows有内置装饰层,但页面没有,我很乐意向您详细解释为什么没有,但我不知道为什么(阅读下文)。但解决方案是,您需要将页面内容包装在装饰器装饰器中,以便为其提供装饰器层

    这里需要明确的是“固定”代码:

    
    


    如果您知道为什么页面没有实现装饰层,并且可以提供更深刻的答案,请随意添加一个解释,作为包含解决方案的另一个答案,即此答案和解释,我会将您的答案更改为正确答案(而不是我的答案)-只是为了促进知识共享;)

    如果在文本框中输入无效数据并单击“退出”,是否存在验证错误?@gleng Yeah,错误会被记录(当我调试时),按钮会被禁用(显示存在验证错误),当我输入valid时,按钮会被重新启用text@gleng-没问题,谢谢你花时间来帮助我!
    <Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ignore="http://www.ignore.com"
        mc:Ignorable="d ignore"
        DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
        Height="576" Width="1163">
    
    <Grid>        
        <TextBox HorizontalAlignment="Left" Text="{Binding Model.title, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
        <Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
    </Grid>
    
    <Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ignore="http://www.ignore.com"
        mc:Ignorable="d ignore"
        DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
        Height="576" Width="1163">
    
    <AdornerDecorator>
        <Grid>        
            <TextBox HorizontalAlignment="Left" Text="{Binding Model.title, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
            <Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
        </Grid>
    </AdornerDecorator>