ItemContainerStyle重写通用样式

我正在从我的App.xaml引用ExpressionDark.xaml,它工作正常,但是当我尝试在ItemsControl中使用ItemContainerStyle时,ItemsControl中的项目将恢复为基本样式。
<ItemsControl Grid.Column="1" VerticalAlignment="Center" Margin="10">
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Margin" Value="5" />
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.Items>
        <TextBlock Text="{Binding Error}" />
        <TextBox Text="{Binding Path=Username,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource validationTemplate}"></TextBox>
        <TextBox Text="{Binding Path=Password,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource validationTemplate}"></TextBox>
        <Button VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding SignInCommand}" IsEnabled="{Binding CanSignIn}" Content="Sign In"></Button>
        <TextBox Text="{Binding Path=Username}"></TextBox>
    </ItemsControl.Items>
</ItemsControl>
我只是试图找到一个很好的控制垂直样式(很容易在项目之间添加边距),所以也许有一种更好的方法不会覆盖App.xaml中指定的样式。 TIA     
已邀请:
如果指定“就地”样式,则会将其视为一种全新的样式。 由于ExpressionDark.xaml的默认样式是该元素的forgotton。 要避免这种情况,您需要做的是:使用BasedOn =参考基本样式
<ItemsControl.ItemContainerStyle>
   <Style BasedOn="{StaticResource Existing}">
      <Setter Property="Margin" Value="5" />
   </Style>
</ItemsControl.ItemContainerStyle>
找到控件的相应默认样式。并使用ExpressionDark.xaml中的Resource-Key替换
Existing
。您可以识别它,因为它将具有正确的
TargetType
属性集:
<Style TargetType="{x:Type ListBoxItem}"> x:Key=...
ListBoxItem是您正在使用的控件(要重新设置) 您可以考虑使用
ListBox
而不是
ItemsControl
,因为它有
ListBoxItem
作为容器。     
他们使用保证金的方式很好,但是当你使用不同的风格然后是
App.xaml
中的风格时,它将不会使用
App.xaml
中的风格。 这是它在WPF中的工作方式,控件使用“最接近”它的样式,并且由于您将此样式直接写入控件,因此它使用该样式。 您可以使用基于
ExpressionDark.xaml
的'BaseOn'属性在
app.xaml
中创建一个新样式,但是您将添加:
<ItemsControl.ItemContainerStyle>
    <Style>
        <Setter Property="Margin" Value="5" />
    </Style>
</ItemsControl.ItemContainerStyle>
    

要回复问题请先登录注册