PathIcon出了什么问题? [英] What is wrong with PathIcon?

查看:70
本文介绍了PathIcon出了什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用样式,则只有第一个PathIcon显示图像。为什么以及如何修复它?

< Page 
x:Class =" App1.MainPage"
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local =" using:App1"
xmlns:d =" http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable =" d">

< Page.Resources>
< Style x:Key =" path1"的TargetType = QUOT; PathIcon">
< Setter Property =" Data"值="M8.25 19.502L2.7 12l5.55-7.5 3.45 4.65L9.447 12l2.25 3-3.45 4.502z"/>
< Setter Property =" Width"值= QUOT; 24英寸; />
< Setter Property =" Height"值= QUOT; 24英寸; />
< / Style>
< Style x:Key =" path2"的TargetType = QUOT; PathIcon">
< Setter Property =" Data"值="M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z"/>
< Setter Property =" Width"值= QUOT; 24英寸; />
< Setter Property =" Height"值= QUOT; 24英寸; />
< / Style>
< /Page.Resources>

< StackPanel Orientation =" Horizo​​ntal" Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}">
< Button>
< PathIcon Style =" {StaticResource path1}"前景= QUOT;海军" />
< / Button>
< Button>
< PathIcon Style =" {StaticResource path1}"前景= QUOT;海军" />
< / Button>
< Button>
< PathIcon Style =" {StaticResource path2}"前景= QUOT;海军" />
< / Button>
< Button>
< PathIcon Style =" {StaticResource path2}"前景= QUOT;海军" />
< / Button>
< Button>
< PathIcon Style =" {StaticResource path2}"前景= QUOT;海军" />
< / Button>
< Button Background =" Aqua">
< PathIcon Data =" M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z"前景= QUOT;海军"宽度= QUOT; 24英寸;高度= QUOT; 24英寸; />
< / Button>
< Button>
< PathIcon Data =" M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z"前景= QUOT;海军"宽度= QUOT; 24英寸;高度= QUOT; 24英寸; />
< / Button>
< Button>
< PathIcon Data =" M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z"前景= QUOT;海军"宽度= QUOT; 24英寸;高度= QUOT; 24英寸; />
< / Button>
< / StackPanel>
< / Page>

结果:


解决方案


Hi Radu2000


这是设计的。如果您在样式中定义数据,则样式将仅实例化一次。但是如果您没有在样式中设置数据
,则样式将正常工作。


这个问题有一个解决方案。您可以将资源中的数据作为字符串写入,并使用
中的字符串资源作为数据属性。


请参考以下代码:



< Page.Resources> 
< Style x:Key =" path1"的TargetType = QUOT; PathIcon">
< Setter Property =" Width"值= QUOT; 24英寸; />
< Setter Property =" Height"值= QUOT; 24英寸; />
< / Style>

< Style x:Key =" path2"的TargetType = QUOT; PathIcon">
< Setter Property =" Width"值= QUOT; 24英寸; />
< Setter Property =" Height"值= QUOT; 24英寸; />
< / Style>
< x:String x:Key =" PathIconData2"> M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z< / x:String>
< x:String x:Key =" PathIconData1"> M8.25 19.502L2.7 12l5.55-7.5 3.45 4.65L9.447 12l2.25 3-3.45 4.502z< / x:String>
< /Page.Resources>
< StackPanel>

< StackPanel Orientation =" Horizo​​ntal" Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}">
< Button Background =" Aqua">
< PathIcon Style =" {StaticResource path1}" Data =" {StaticResource PathIconData1}"前景= QUOT;海军" />
< / Button>
< Button Background =" Red">
< PathIcon Style =" {StaticResource path1}" Data =" {StaticResource PathIconData1}"前景= QUOT;海军" />
< / Button>
< Button Background =" Brown">
< PathIcon Style =" {StaticResource path2}" Data =" {StaticResource PathIconData2}"前景= QUOT;海军" />
< / Button>
< Button Background ="黄色">
< PathIcon Style =" {StaticResource path2}" Data =" {StaticResource PathIconData2}"前景= QUOT;海军" />
< / Button>

< / StackPanel>


< / StackPanel>






当我运行应用程序时,它看起来像这样:



< span style ="font-size:10.5pt; font-family:'Segoe UI',sans-serif;颜色:#454545">



最好的问候,


罗伊



Only first PathIcon shows image, if using styles. Why and how it can be fixed?

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <Style x:Key="path1" TargetType="PathIcon">
            <Setter Property="Data" Value="M8.25 19.502L2.7 12l5.55-7.5 3.45 4.65L9.447 12l2.25 3-3.45 4.502z"/>
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>
        <Style x:Key="path2" TargetType="PathIcon">
            <Setter Property="Data" Value="M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z"/>
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>
    </Page.Resources>

    <StackPanel Orientation="Horizontal" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button>
            <PathIcon Style="{StaticResource path1}" Foreground="Navy"/>
        </Button>
        <Button>
            <PathIcon Style="{StaticResource path1}" Foreground="Navy"/>
        </Button>
        <Button>
            <PathIcon Style="{StaticResource path2}" Foreground="Navy"/>
        </Button>
        <Button>
            <PathIcon Style="{StaticResource path2}" Foreground="Navy"/>
        </Button>
        <Button>
            <PathIcon Style="{StaticResource path2}" Foreground="Navy"/>
        </Button>
        <Button Background="Aqua">
            <PathIcon Data="M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z" Foreground="Navy" Width="24" Height="24"/>
        </Button>
        <Button>
            <PathIcon Data="M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z" Foreground="Navy" Width="24" Height="24"/>
        </Button>
        <Button>
            <PathIcon Data="M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z" Foreground="Navy" Width="24" Height="24"/>
        </Button>
    </StackPanel>
</Page>

Result:

解决方案

Hi Radu2000

This is by design. If you define the data in the style, the style will only be instantiated once. But if you do not set data in the style, the style would work correctly as general.

There is a solution for this issue. You could write the data in the resources as a string and use the string resources in the data property.

Please refer the following code:

    <Page.Resources>
        <Style x:Key="path1" TargetType="PathIcon">
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>

        <Style x:Key="path2" TargetType="PathIcon">
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>
        <x:String x:Key="PathIconData2">M12.45 24l8.85-12-8.85-12h-6.9l9 12-9 12h6.9z</x:String>
        <x:String x:Key="PathIconData1">M8.25 19.502L2.7 12l5.55-7.5 3.45 4.65L9.447 12l2.25 3-3.45 4.502z</x:String>
    </Page.Resources>
    <StackPanel>

        <StackPanel Orientation="Horizontal" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Button Background="Aqua">
                <PathIcon Style="{StaticResource path1}" Data="{StaticResource PathIconData1}"  Foreground="Navy"/>
            </Button>
            <Button  Background="Red">
                <PathIcon Style="{StaticResource path1}"  Data="{StaticResource PathIconData1}"  Foreground="Navy"/>
            </Button>
            <Button Background="Brown">
                <PathIcon Style="{StaticResource path2}"  Data="{StaticResource PathIconData2}"  Foreground="Navy"/>
            </Button>
            <Button Background="Yellow">
                <PathIcon Style="{StaticResource path2}"  Data="{StaticResource PathIconData2}"  Foreground="Navy"/>
            </Button>

        </StackPanel>

       
    </StackPanel>


When I run the app, it looks like this :

Best regards,

Roy


这篇关于PathIcon出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆