Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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 Can';t创建几何图形的多个实例_Wpf_Xaml - Fatal编程技术网

Wpf Can';t创建几何图形的多个实例

Wpf Can';t创建几何图形的多个实例,wpf,xaml,Wpf,Xaml,我的应用程序中的图标作为几何图形存储在资源目录中。例如: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Viewbox x:Key="ViewboxIconClose" Width="16" Height=

我的应用程序中的图标作为几何图形存储在资源目录中。例如:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox x:Key="ViewboxIconClose"
         Width="16"
         Height="16">
    <Rectangle Width="16" Height="16">
        <Rectangle.Fill>
            <DrawingBrush>
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
                            <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1M9.4141,8L13.9571,12.543 12.5431,13.957 8.0001,9.414 3.4571,13.957 2.0431,12.543 6.5861,8 2.0431,3.457 3.4571,2.043 8.0001,6.586 12.5431,2.043 13.9571,3.457z" />
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>
        </Rectangle.Fill>
    </Rectangle>
</Viewbox>

此图标的使用方式如下:

<Button>
    <StaticResource ResourceKey="ViewboxIconClose" />
</Button>

现在我的问题是:
如果我在其他地方使用这个几何体,它只能在一个地方工作。例如,如果我在菜单中使用此几何体,按钮上的几何体将立即消失,我打开菜单。

您可以使用x:Shared=false来解决此问题,但我可能会使用样式和图像。图像应该比带有画笔和视口框的矩形更有效

    Title="MainWindow" Height="350" Width="525"

    xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
    >
<Window.Resources>
    <Style x:Key="CloseIcon" TargetType="Image">
        <Setter Property="Stretch" Value="Uniform"/>
        <Setter Property="Source">
            <Setter.Value>
                <DrawingImage PresentationOptions:Freeze="True">
                    <DrawingImage.Drawing>
                        <DrawingGroup>
                            <GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
                            <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1M9.4141,8L13.9571,12.543 12.5431,13.957 8.0001,9.414 3.4571,13.957 2.0431,12.543 6.5861,8 2.0431,3.457 3.4571,2.043 8.0001,6.586 12.5431,2.043 13.9571,3.457z" />
                        </DrawingGroup>
                    </DrawingImage.Drawing>
                </DrawingImage>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <StackPanel>
        <Grid Height="100" Width="100" Background="Red">
            <Image  Style="{StaticResource CloseIcon}"/>
        </Grid>
        <Grid Height="30" Width="30" Background="Blue">
            <Image  Style="{StaticResource CloseIcon}"/>
        </Grid>
    </StackPanel>
</Grid>
Title=“MainWindow”Height=“350”Width=“525”
xmlns:PresentationOptions=”http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
>

根据此特定要求,您可以仅使用一个几何图形作为路径的数据。几何图形不是视觉效果