2013-05-30 35 views
4

我有一個BindingGroup在網格:從ErrorTemplate訪問Validation.Errors

<Grid x:Name="участнКонтейн" DataContext="{Binding Source={StaticResource участнПк}}" 
    Grid.RowSpan="1" Grid.Row="1" HorizontalAlignment="Center"> 
    <Grid.BindingGroup> 
    <BindingGroup NotifyOnValidationError="True"> 
     <BindingGroup.ValidationRules> 
     <цл:валидУчастн ValidationStep="ConvertedProposedValue" /> 
     </BindingGroup.ValidationRules> 
    </BindingGroup> 
    </Grid.BindingGroup> 
    <Grid.Style> 
    <Style> 
     <Setter Property="Validation.ErrorTemplate" Value="{StaticResource BindingGroupШаблОш}" /> 
    </Style> 
    </Grid.Style> 
    ... 

而且我有我的網ErrorTemplate:

<ControlTemplate x:Key="BindingGroupШаблОш"> 
    <Border BorderBrush="Blue" BorderThickness="2"> 
    <StackPanel> 
     <Label Content="My BindingGroup Error should be here!"></Label> 
     <AdornedElementPlaceholder /> 
    </StackPanel> 
    </Border> 
</ControlTemplate> 

我想訪問Validation.Errors [0 ] .ErrorContent從我的ControlTemplate顯示在我的Label中。可能嗎?你可以幫我嗎?

+0

+1有一個良好的,但令人驚訝的罕見問題。我完全同意這種解決方案並未廣泛發佈。我剛剛在MSDN上向Validation.ErrorTemplate附加屬性頁面發佈了一個建議,要求他們添加這個'DataContext = Validation.Errors'信息,但我們只能等待看看他們是否執行了任何操作。 – Sheridan

回答

3

嘗試

<ControlTemplate x:Key="BindingGroupШаблОш"> 
    <Border BorderBrush="Blue" BorderThickness="2"> 
    <StackPanel> 
     <Label Content="{Binding Path=[0].ErrorContent}"></Label> 
     <AdornedElementPlaceholder /> 
    </StackPanel> 
    </Border> 
</ControlTemplate> 
+0

謝謝!這適用於我! –

+1

你是怎麼知道的?你在哪裏讀到這個? –

+1

我花了很多時間閱讀MSDN,但我沒有找到解決方案。而且非常簡單。它寫在哪裏?微軟如何認爲我應該知道這一點? –