内容仅在给定时间显示在单个元素中 [英] Content Only being shown in a Single element at a given time

查看:30
本文介绍了内容仅在给定时间显示在单个元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在特定的滚动查看器中显示一堆带有图标的名称.有两种主要类型的图标需要显示,但是尽管这两种类型的图标都令人厌恶地显示,但一次只有一个元素得到这个图标.

I am Trying to Display a bunch of Names with an Icon in a particular Scroll viewer. There are 2 main types of Icons that need to be displayed , However although both Types pf Icons are disgustingly being displayed only One Element gets this Icon at a time.

推荐答案

这里是一个最小的示例,用于验证具有 x:Shared="False" 的资源可用于呈现多次出现相同的图标,而使用共享资源(默认),只呈现最后一次出现:

Here is a minimal example that verifies, that a resource with x:Shared="False" can be used to render multiple occurences of the same icon, while with a shared resource (default), only the last occurence is rendered:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        x:Class="Application1.MainWindow">
    <Window.Resources>
        <Canvas x:Key="FileIconShared" Width="20" Height="20">
            <Path Stroke="Black" Fill="White"  Data="M20,4L4,4A2,2,0,0,0,2,6L2,18A2,2,0,0,0,4,20L20,20A2,2,0,0,0,22,18L22,6A2,2,0,0,0,20,4 M20,18L4,18 4,8 12,13 20,8 20,18 M20,6L12,11 4,6 4,6 20,6 20,6z">
            </Path>
        </Canvas>
        <Canvas x:Key="FileIconNotShared" x:Shared="False" Width="20" Height="20">
            <Path Stroke="Black" Fill="White"  Data="M20,4L4,4A2,2,0,0,0,2,6L2,18A2,2,0,0,0,4,20L20,20A2,2,0,0,0,22,18L22,6A2,2,0,0,0,20,4 M20,18L4,18 4,8 12,13 20,8 20,18 M20,6L12,11 4,6 4,6 20,6 20,6z">
            </Path>
        </Canvas>
    </Window.Resources>
    <Grid>
        <StackPanel HorizontalAlignment="Left" Width="100">
            <TextBlock>Shared 1</TextBlock>
            <ContentControl Content="{StaticResource FileIconShared}"/>
            <TextBlock>Shared 2</TextBlock>
            <ContentControl Content="{StaticResource FileIconShared}"/>
            <TextBlock>Not Shared 1</TextBlock>
            <ContentControl Content="{StaticResource FileIconNotShared}"/>
            <TextBlock>Not Shared 2</TextBlock>
            <ContentControl Content="{StaticResource FileIconNotShared}"/>
        </StackPanel>
    </Grid>
</Window>

效果:第一个图标丢失,第二到第四个被渲染.

Effect: First Icon is missing, 2nd to 4th is rendered.

我不能说您将如何将其应用到您的项目中,因为缺少关于您的资源的确切定义位置以及您的数据模板的配置方式的大量信息.

I can't say how you would apply this to your project, since to much information is missing on where exactly your resources are defined and how exactly your datatemplate is configured.

这篇关于内容仅在给定时间显示在单个元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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