c# - Open referenced control in a new window -



c# - Open referenced control in a new window -

issue

i want load referenced command main window new window. referenced command kid of main window, causing next exception when attempting render new window:

system.argumentexception unhandled:

must disconnect specified kid current parent visual before attaching new parent visual.

i not want disconnect main window , cannot create new instance of command since not know how it's instantiated or members applied.

background

i'm developing application allows developers extend application additional views of configuration options. container of these views may turn out little big view extensions (imagine scheduling command agendas example), wish provide user ability open extended view in new window.

code

so far i've created behavior attach hyperlinks opens new window referenced command upon click event. next code basic implementation demonstrate intention:

public class expandviewbehavior : behavior<hyperlink> { public static dependencyproperty viewproperty = dependencyproperty.register("view", typeof(object), typeof(expandviewbehavior)); public object view { { homecoming getvalue(viewproperty); } set { setvalue(viewproperty, value); } } protected override void onattached() { this.associatedobject.click += associatedobject_click; } void associatedobject_click(object sender, routedeventargs e) { if (view != null) { var window = new window() { content = view }; window.show(); } } }

attached hyperlink in main window, referencing simple textbox load in new window. i system.windows.interactivity namespace , local project namespace.

xmlns:local="clr-namespace:wpfapplication" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" ... <stackpanel> <textblock> <hyperlink> <i:interaction.behaviors> <local:expandviewbehavior view="{binding source={x:reference somecontrol}}" /> </i:interaction.behaviors> <textblock text="(open in new window)" /> </hyperlink> </textblock> <textbox x:name="somecontrol" /> </stackpanel>

my question is, there way load referenced command without disconnecting main window?

as can't display same command in 2 places @ once, either need disconnect command main window (as noted in error text), or create re-create of command place kid window.

you can clone command exporting xaml, , create new command xaml. see reply how can clone wpf object? more details.

c# wpf xaml

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -