0

我对写在名为“PControls”的单独库中的 CostumControl 中的图像有疑问。

在该库中,我有一个名为“Resources”的文件夹,其中包含图像“group.png”、“filter.png”和“sort.png”。当我尝试在另一个项目中使用我的控件时,图像没有出现......

我已经尝试过以下方法:

  • 所有图像构建操作都设置为资源(不是嵌入式资源)

  • 图像源属性设置为每个可能的 URI(例如“/PControl;/component/Resources/filter.png”)“../Resources/filter.png”是 VS 似乎找到图像的唯一值,因为没有显示错误

这是我的样式的一部分 - 它基本上是标准 WPF DataGrid 的样式,通过工具栏增强,其中包含应显示图像的按钮:

<Style TargetType="{x:Type local:PDataGrid}">
    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="BorderBrush" Value="#FF688CAF"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:PDataGrid}">
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
                    <ScrollViewer x:Name="DG_ScrollViewer" Focusable="false">
                        <ScrollViewer.Template>
                            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="25"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>

                                    <Button Command="{x:Static local:PDataGrid.SelectAllCommand}" Focusable="false" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type local:PDataGrid}}}" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type local:PDataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type local:PDataGrid}}}"/>
                                    <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1" Grid.ColumnSpan="2" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type local:PDataGrid}}}"/>
                                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" Grid.ColumnSpan="2" Grid.Row="1"/>

                                    <ToolBarTray Orientation="Vertical" Grid.Row="1" Grid.Column="2" IsLocked="True">
                                        <ToolBar Band="1" BandIndex="1" >
                                            <Button Width="24" Height="24" ToolTip="Sort">
                                                <Image Source="../Resources/sort.png" />
                                            </Button>
                                            <Button Width="24" Height="24" ToolTip="Filter">
                                                <Image Source="../Resources/filter.png" />
                                            </Button>
                                            <Button Width="24" Height="24" ToolTip="Group">
                                                <Image Source="../Resources/group.png" />
                                            </Button>
                                        </ToolBar>
                                    </ToolBarTray>
                                    ...
4

1 回答 1

0

现在开始工作了!

我确定我昨天已经尝试过了,但现在以下工作:

<ToolBarTray Orientation="Vertical" Grid.Row="1" Grid.Column="2" IsLocked="True">
    <ToolBar Band="1" BandIndex="1" >
        <Button Width="24" Height="24" ToolTip="Sort">
            <Image Source="pack://application:,,,/PControls;component/Resources/sort.png" />
        </Button>
        <Button Width="24" Height="24" ToolTip="Filter">
            <Image Source="pack://application:,,,/PControls;component/Resources/filter.png" />
        </Button>
        <Button Width="24" Height="24" ToolTip="Group">
            <Image Source="pack://application:,,,/PControls;component/Resources/group.png" />
        </Button>
    </ToolBar>
</ToolBarTray>
于 2012-07-21T15:10:14.173 回答