WPF:如何忽略具体控件的定义样式

时间:2013-08-19 08:56:03

标签: wpf

我在资源字典中定义了Rectangle控件样式(对于Rectangle的类型),它也反映了Menu控件的样式。

如何忽略菜单的这些设置并将其保留为(仅)矩形? - 画布中的绘图目的.... Rectangle控件从后面的代码动态添加到画布。在主窗口中有dockpanel,网格,菜单,文本块和画布控件。矩形样式也会损坏Menu的样式属性(需要保留默认样式)。

感谢您的建议

主窗口控件:

<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LastChildFill="True">
        <Grid DockPanel.Dock="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Menu Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Height="21" Name="menu" Style="{StaticResource ResourceKey=menuStyle}">
            <MenuItem Header="File">
                <MenuItem Header="Open image" Command="{Binding DoCommand}" CommandParameter="OpenImage"/>
                <MenuItem Header="Exit" Command="{Binding DoCommand}" CommandParameter="Exit"/>
            </MenuItem>
        </Menu>
            <RadioButton Margin="5" Grid.Row="1" Grid.Column="0" Content="Text selection" GroupName="ObjectType" IsChecked="{Binding Path=ObjectType, Mode=TwoWay, Converter={StaticResource ResourceKey=RadioButtonTypeConverter}, ConverterParameter=Text}" />
            <RadioButton Margin="5" Grid.Row="1" Grid.Column="1" Content="Picture selection" GroupName="ObjectType" IsChecked="{Binding Path=ObjectType, Mode=TwoWay, Converter={StaticResource ResourceKey=RadioButtonTypeConverter}, ConverterParameter=Picture}" />
        </Grid>
        <pt:PropertyControl DockPanel.Dock="Right" SelectedObject="{Binding SelectedObject}" MinWidth="150"/>

        <TextBlock DockPanel.Dock="Bottom" Height="100" Margin="5" Background="#FFF9F9F9">

        </TextBlock>
        <Canvas Name="canvas" MouseLeftButtonDown="Canvas_MouseLeftButtonDown" Background="White" Width="{Binding ElementName=ImgEdit, Path=Width}" Height="{Binding ElementName=ImgEdit, Path=Height}" MinWidth="300" MinHeight="100" VerticalAlignment="Top" MouseMove="canvas_MouseMove" MouseLeftButtonUp="canvas_MouseLeftButtonUp" >

            <Image x:Name="ImgEdit" Source="{Binding BackgroundImage}" HorizontalAlignment="Center" VerticalAlignment="Center" />
        </Canvas>
    </DockPanel>

我的Style资源字典的代码:

<Style TargetType="{x:Type Rectangle}" >
        <Setter Property="Fill" Value="Yellow" />
        <Setter Property="Opacity" Value="0.2"/>
        <Setter Property="StrokeThickness" Value="2"/>
        <Setter Property="Stroke" Value="Red" />
    </Style>

0 个答案:

没有答案