“Open in Expression Blend…” missing for WPF projec

2019-08-10 07:34发布

i'm having a problem. When i create a WPF project and want to see the link to "open in expression blend" - it is not there like a Silverlight project does. I can use the "open with" link to gain access to blend and then open blend and work from there. (That is the work around). However, from internet searching i found out that expression blend has to be installed before visual studio (not vice-a-versa) in order to see "open in expression blend" with a wpf project. This happens in Window 7 x64 OS and x32 OS. I also found when working with "regedit" that x64 and x32 are setup differently with respect to expression blend.

Somebody please help in correcting this problem.

1条回答
放我归山
2楼-- · 2019-08-10 08:15

It seems that this feature simply isn't available for WPF projects. When it works, and it doesn't always work, it only works in Silverlight projects. However what "Open in Expression Blend..." does is not very complicated so here is a Visual Studio macro to take it's place.

Public Sub OpenInExpressionBlend()
    Dim blendPath As String = Nothing
    Dim key As String = "SOFTWARE\Microsoft\Expression\Blend\VS"
    Dim registryKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(key)
    If Not registryKey Is Nothing Then
        blendPath = registryKey.GetValue("BlendLaunchPath")
        registryKey.Close()
    End If
    If blendPath Is Nothing Then
        MsgBox("Cannot find Blend", MsgBoxStyle.Exclamation, "Open in Expression Blend")
        Return
    End If
    If DTE.SelectedItems.Count <> 1 Then
        MsgBox("Not just one item selected", MsgBoxStyle.Exclamation, "Open in Expression Blend")
        Return
    End If
    Dim item As SelectedItem = DTE.SelectedItems.Item(1)
    If Not TypeOf item.ProjectItem Is ProjectItem Then
        MsgBox("Not a project item", MsgBoxStyle.Exclamation, "Open in Expression Blend")
        Return
    End If
    Dim projectItem As ProjectItem = item.ProjectItem
    Dim project As Project = projectItem.ContainingProject
    Dim file As String = projectItem.Name
    If file.Substring(file.Length - 5) <> ".xaml" Then
        MsgBox("Not a xaml file", MsgBoxStyle.Exclamation, "Open in Expression Blend")
        Return
    End If
    While TypeOf projectItem.Collection.Parent Is ProjectItem
        projectItem = CType(projectItem.Collection.Parent, ProjectItem)
        file = projectItem.Name & "\" & file
    End While
    file = """" & file & """"
    Dim projectPath As String = """" & project.FullName & """"
    Dim blendArgs As String = projectPath & " /file:" & file
    Dim process As System.Diagnostics.Process = New System.Diagnostics.Process()

& blendArgs) process.Start(blendPath, blendArgs) End Sub

Update:

To use this, add the macro using the Macro IDE and then add it to the project item context menu like this:

Tools -> Customize -> Commands -> Context Menu: Project and Solution Context Menus | Item -> Add Command... -> Categories: Macro -> Commands: Macros.MyMacros.Personal.OpenInExpressionBlend -> OK

Modify Selection -> Name: Open in Expression Blend...

Move Down: (move below Open With...)

Note: the command will depend on which Module you added it to.

查看更多
登录 后发表回答