Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
WPF IDataErrorInfo问题_Wpf_Prism 4_Idataerrorinfo_Adornerdecorator - Fatal编程技术网

WPF IDataErrorInfo问题

WPF IDataErrorInfo问题,wpf,prism-4,idataerrorinfo,adornerdecorator,Wpf,Prism 4,Idataerrorinfo,Adornerdecorator,我在过去的应用程序中使用了WPF和IDataErrorInfo,通过在装饰器中放置图像并向图像添加工具提示(如下所示),通过controltemplate向用户显示错误 <Style x:Key="textStyle" TargetType="TextBox"> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate>

我在过去的应用程序中使用了WPF和IDataErrorInfo,通过在装饰器中放置图像并向图像添加工具提示(如下所示),通过controltemplate向用户显示错误

<Style x:Key="textStyle" TargetType="TextBox">
  <Setter Property="Validation.ErrorTemplate">
    <Setter.Value>
      <ControlTemplate>
        <DockPanel LastChildFill="True">
          <Border BorderBrush="Orange"
                  BorderThickness="2"
                  CornerRadius="4"
                  SnapsToDevicePixels="True">
            <Border.Effect>
              <DropShadowEffect BlurRadius="10"
                                ShadowDepth="0"
                                Color="Orange" />
            </Border.Effect>
            <DockPanel>
              <Image Width="16"
                     Height="16"
                     Margin="-20,0,0,0"
                     HorizontalAlignment="Left"
                     VerticalAlignment="Center"
                     RenderOptions.BitmapScalingMode="HighQuality"
                     Source="{StaticResource imgError}"
                     ToolTip="{Binding ElementName=adornedElement,
                                       Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"
                     ToolTipService.ShowDuration="30000" />
              <AdornedElementPlaceholder Name="adornedElement" />
            </DockPanel>
          </Border>
        </DockPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

在ViewModel中适当实现IDataErrorInfo并在视图中相应设置文本框后,将显示图像和工具提示

<TextBox Name="txt"
         Grid.Column="0"
         Height="40"
         Background="Aqua"
         Style="{StaticResource textStyle}"
         Text="{Binding Path=Text,
                        UpdateSourceTrigger=PropertyChanged,
                        ValidatesOnDataErrors=True}" />
<TextBlock Grid.Column="1"
           Height="40"
           Background="AliceBlue"
           Text="{Binding ElementName=txt,
                          Path=(Validation.Errors).CurrentItem.ErrorContent}" />

上述代码在我以前的应用程序中正确显示,并在文本块确认的图像工具提示中显示错误

然而,在我目前使用Prism构建的应用程序中,我无法显示图像。TextBlock会正确更新,我可以通过样式触发器将错误设置为TextBox工具提示,而不会出现任何问题。问题是我似乎无法在装饰器中显示图像(或任何其他内容)。不会显示图像,也不会更改边框

以前的应用程序与现在的不同之处在于,视图位于ContentControl中的一个区域中,我使用依赖项注入将viewmodel注入视图构造函数并设置DataContext


我不明白为什么它以前不起作用。我认为我可能需要在某个地方包括一个装饰设计师,但我很困惑,在哪里尝试过,但没有成功。有什么办法可以确保显示装饰器吗?

使用装饰器来包装包含texbox的元素,一切正常。

我是对的-缺少装饰器的要求。我必须将文本框或其容器包装在AdorneDecorator标记中,图像等才能正确显示