1

我在资源字典中定义了 Rectangle 控件样式(对于 Rectangle 的类型),它也反映了 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 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>
4

0 回答 0