c# - WPF and Workflow foundation don't work together -


i have strange problem. i've created wpf project in 2012 or 2013 vs doesn't matter. use .net 4.5.

  1. i add new activity (workflow class) project. name customactivity.
  2. then add new class has got attached property, example below:

    public class attachedobject : dependencyobject { public static readonly dependencyproperty nameproperty = dependencyproperty.registerattached(               "name",               typeof(string),               typeof(attachedobject),               new frameworkpropertymetadata( string.empty,frameworkpropertymetadataoptions.affectsrender));  public static void setname(contentcontrol element, string value) {     element.setvalue(nameproperty, value); }  public static string getname(contentcontrol element) {     return (string)element.getvalue(nameproperty); } } 
  3. the last step change mainwindow class way:

    public mainwindow() {     initializecomponent();     var activity = new customactivity(); } 
    <window x:class="wpfapplication1.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:wpfapplication1="clr-namespace:wpfapplication1;assembly=wpfapplication1"         title="mainwindow" height="350" width="525">     <grid>         <contentcontrol wpfapplication1:attachedobject.name="mainarea"/>     </grid> </window> 

the problem doesn't compile because of below error:

error 1 type or namespace name 'customactivity' not found (are missing using directive or assembly reference?) wpfapplication1\mainwindow.xaml.cs 13 32 wpfapplication1

customactivity has default namespace. in obj folder there customactivity.g.cs generated, have no idea what's going on. it's 100% reproducible. when remove using of customactivity or using of attachedobject xaml problem disappear.

try replacing this:

xmlns:wpfapplication1="clr-namespace:wpfapplication1;assembly=wpfapplication1" 

with this

 xmlns:wpfapplication1="clr-namespace:wpfapplication1" 

the error you're seeing due "known" issue in wpf applications xaml namespaces reference clr namespace current assembly in don't require full assembly qualified name. if declare xaml namespace references clr namespace assembly, have specify full name (with ;[assemblyname] syntax).

workflow foundation has nothing it.

edit: didn't realize xaml activity. still, can make work, maybe, few hacks, wouldn't recommend it. reason error due different code generation , build action vs uses when creating xaml artifacts wpf (page):

system.windows.application.loadcomponent(this, resourcelocater); 

and when creating xaml activities (xamlappdef):

 typeof(customactivity).assembly.getmanifestresourcestream(resourcename); 

if turn customactivity xaml build action page, whole thing compile - i'm guessing else might broken someplace else...or not, knows. guess these 2 kinds of xaml not meant live in vs wpf application project template. can still define activities in wf activity library, way activities more reusable other projects, wpf, console or services.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -