VS 2015 中的 Workflow Foundation 4 - 活动工具箱位图不显示

问题描述 投票:0回答:2

我已经阅读了多个关于此的教程/博客/stackoverflow 问题,包括以下内容:

还有更多。

其中大多数都已经过时了。 有些人建议活动设计器库名称应以 Design.dll 结尾,另一些人则建议它应以 VisualStudio.Design.dll 结尾。 有人说该库应该部署到 Visual Studio bin 路径,其他人说这不是必需的。

这一切都非常令人困惑。

我可以使活动工具箱位图仅在使用时正确显示 ToolboxBitmapAttribute 直接在 Activity 上,并且仅当嵌入的 bmp 图标位于 Activity 库中时,例如:

[ToolboxBitmap(typeof(MyActivity), "Resources.Bitmaps.MyActivity.bmp"]
public class MyActivity : CodeActivity
{
}

如果我将位图移动到活动设计器库,引用活动库中的活动设计器库,并直接在活动上使用 ToolboxBitmapAttribute (使用正确的嵌入路径并使用活动设计器库中的类型) - 它不起作用.

[ToolboxBitmap(typeof(MyActivityDesigner), "Resources.Bitmaps.MyActivity.bmp"]
public class MyActivity : CodeActivity
{
}

如果我使用 ActivityDesigner 库中的 IRegisterMetadata 接口,将 ToolboxBitmapAttribute 注册到元数据存储中的 MyActivity 类型:

AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(MyActivity), new DesignerAttribute(typeof(MyActivityDesigner)));
builder.AddCustomAttributes(typeof(MyActivity), new ToolboxBitmapAttribute(typeof(MyActivityDesigner), "Resources.Bitmaps.MyActivity.bmp"));
MetadataStore.AddAttributeTable(builder.CreateTable());

仍然没有活动的工具箱位图。

活动设计器工作得很好!

看来VS正在加载MyActivities.Design.dll库,但由于某种原因忽略了ToolboxBitmapAttribute。

我将不胜感激对此的提示。

bitmap visual-studio-2015 workflow-foundation-4 workflow-foundation toolbox
2个回答
0
投票

您可能想尝试 ActivityDesigner 的 Icon 属性。确保图像位于活动设计者的项目中并标记为“构建操作上的资源”:

<sap:ActivityDesigner.Icon>
    <DrawingBrush>
        <DrawingBrush.Drawing>
            <ImageDrawing>
                <ImageDrawing.Rect>
                    <Rect Location="0,0" Size="25,25" ></Rect>
                </ImageDrawing.Rect>
                <ImageDrawing.ImageSource>
                    <BitmapImage UriSource="MyActivityIcon.png" />
                </ImageDrawing.ImageSource>
            </ImageDrawing>
        </DrawingBrush.Drawing>
    </DrawingBrush>
</sap:ActivityDesigner.Icon>

0
投票

如果我理解正确,您会希望活动设计器图标也出现在工具箱中以及您的自定义活动中。如果是这样,那么您将需要使用图标字典并使用 svg 来实现相同的效果。在此输入代码

看起来像下面的东西 -

 <sap:ActivityDesigner.Icon>
    <DrawingBrush Stretch="Uniform" Drawing="{Binding Path=ModelItem, Converter={StaticResource ActivityIconConverter}, ConverterParameter=pack://application:\,\,\,/Company.FirstCategory.Activities.Design;component/themes/icons.xaml}" />
</sap:ActivityDesigner.Icon>

所以你的icons.xaml看起来像->。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


    <!--Subtraction Icon-->
<DrawingGroup x:Key="NewTextDocument499ff37984df451cb178fc5a99dc692e_0">
  <DrawingGroup.ClipGeometry>
    <RectangleGeometry Rect="0,0,100,100" />
  </DrawingGroup.ClipGeometry>
  <GeometryDrawing>
    <GeometryDrawing.Brush>
      <LinearGradientBrush StartPoint="0.1,0" EndPoint="0.9,0" MappingMode="RelativeToBoundingBox" SpreadMethod="Pad" Opacity="1">
        <GradientStop Color="#FFE3E3E3" Offset="0" />
        <GradientStop Color="#FFFFFFFF" Offset="1" />
      </LinearGradientBrush>
    </GeometryDrawing.Brush>
    <GeometryDrawing.Geometry>
      <EllipseGeometry RadiusX="50" RadiusY="50" Center="50,50" />
    </GeometryDrawing.Geometry>
  </GeometryDrawing>
  <GeometryDrawing Brush="#FF77397C">
    <GeometryDrawing.Geometry>
      <EllipseGeometry RadiusX="5" RadiusY="5" Center="40,20" />
    </GeometryDrawing.Geometry>
  </GeometryDrawing>
  <GeometryDrawing Brush="#FF245BAA">
    <GeometryDrawing.Geometry>
      <EllipseGeometry RadiusX="5" RadiusY="5" Center="50,20" />
    </GeometryDrawing.Geometry>
  </GeometryDrawing>
  <GeometryDrawing Brush="#FFDC4226">
    <GeometryDrawing.Geometry>
      <EllipseGeometry RadiusX="5" RadiusY="5" Center="60,20" />
    </GeometryDrawing.Geometry>
  </GeometryDrawing>
  <DrawingGroup>
    <GeometryDrawing Brush="#FF000000">
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Figures="M44.6401443481445,29.51904296875C47.7846755981445,29.5190448760986 50.1516189575195,30.2083358764648 51.7409744262695,31.5869140625 53.3303298950195,32.9654960632324 54.1648826599121,34.8055038452148 54.2446365356445,37.10693359375L49.1860427856445,37.3291015625C48.9695701599121,36.0416679382324 48.5052947998047,35.115966796875 47.7932205200195,34.552001953125 47.0811424255371,33.988037109375 46.0130271911621,33.7060546875 44.5888748168945,33.7060546875 43.1191482543945,33.7060546875 41.9684295654297,34.0079765319824 41.1367263793945,34.61181640625 40.601245880127,34.9991874694824 40.3335037231445,35.517578125 40.3335037231445,36.1669921875 40.3335037231445,36.7594413757324 40.584156036377,37.2664413452148 41.0854568481445,37.68798828125 41.7234764099121,38.2234725952148 43.2729568481445,38.78173828125 45.7338943481445,39.36279296875 48.1948318481445,39.94384765625 50.0149002075195,40.5448417663574 51.1940994262695,41.165771484375 52.3732986450195,41.7867050170898 53.2961502075195,42.635498046875 53.9626541137695,43.712158203125 54.6291580200195,44.788818359375 54.9624099731445,46.1189804077148 54.9624099731445,47.70263671875 54.9624099731445,49.13818359375 54.5636444091797,50.4825859069824 53.7661209106445,51.73583984375 52.9685935974121,52.9890937805176 51.8406639099121,53.9204902648926 50.3823318481445,54.530029296875 48.9239959716797,55.1395683288574 47.1067771911621,55.4443359375 44.9306716918945,55.4443359375 41.7633514404297,55.4443359375 39.3308982849121,54.7123222351074 37.6333084106445,53.248291015625 35.935718536377,51.7842597961426 34.9217185974121,49.65087890625 34.5913162231445,46.84814453125L39.5131912231445,46.36962890625C39.8094139099121,48.0216484069824 40.4104080200195,49.2350273132324 41.3161697387695,50.009765625 42.2219314575195,50.7845039367676 43.4438552856445,51.171875 44.9819412231445,51.171875 46.6111717224121,51.171875 47.8387908935547,50.8272285461426 48.6648025512695,50.137939453125 49.4908103942871,49.4486503601074 49.9038162231445,48.642578125 49.9038162231445,47.7197265625 49.9038162231445,47.1272773742676 49.7300682067871,46.6231307983398 49.3825759887695,46.207275390625 49.0350799560547,45.7914237976074 48.4283905029297,45.4296875 47.5625076293945,45.1220703125 46.9700584411621,44.9169921875 45.6199607849121,44.5524101257324 43.5122146606445,44.0283203125 40.8006248474121,43.3561210632324 38.8979568481445,42.5301132202148 37.8042068481445,41.55029296875 36.2661209106445,40.1717147827148 35.4970779418945,38.4912109375 35.4970779418945,36.5087890625 35.4970779418945,35.2327499389648 35.858814239502,34.039306640625 36.5822830200195,32.928466796875 37.3057518005371,31.817626953125 38.3482322692871,30.9716796875 39.7097244262695,30.390625 41.071216583252,29.8095722198486 42.7146873474121,29.5190448760986 44.6401443481445,29.51904296875z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
  </DrawingGroup>
  <GeometryDrawing Brush="#FF595959">
    <GeometryDrawing.Geometry>
      <RectangleGeometry RadiusX="2" RadiusY="2" Rect="10,78,80,5" />
    </GeometryDrawing.Geometry>
  </GeometryDrawing>
</DrawingGroup>
<DrawingBrush x:Key="SubtractionIcon" Drawing="{StaticResource NewTextDocument499ff37984df451cb178fc5a99dc692e_0}" />

因为它是一个 svg,所以它可以缩放到任何尺寸(小或大),并且当您将其绑定到 ActivityDesigner.xaml 中时也会出现在工具箱中

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.