Pseudo-cracking componentone Silverlight Control

Source: Internet
Author: User

Multiple controls are used in Silverlight development. Sometimes the existing controls cannot meet the requirements, so many third parties provide a variety of controls. Among them, there is componentone, of course, charge, $895.

If it is not registered, C1: c1nagscreen. Nag = "true" will be automatically inserted in the XAML when the C1 control is referenced, for example:

<C1datetime: c1datetimepicker C1: c1nagscreen. Nag = "true"/>

The following page is displayed when the program is started:

In fact, other functions are quite normal, that is, this box is quite annoying, the box is hateful, but it only plays once.

In this case, you only need to find a way to remove this box, rather than implementing the crack registration function.

Use reflector to open c1.silverlight. dll and find c1nagscreen. See the following code:

Private Static bool alreadynagged;
Public static readonly dependencyproperty nagproperty;

// Methods
Static c1nagscreen ()
{
Nagproperty = dependencyproperty. registerattached ("nag", typeof (bool), typeof (c1nagscreen), new propertymetadata (delegate (dependencyobject S, dependencypropertychangedeventargs e ){
Frameworkelement element = (frameworkelement) S;
Element. Loaded + = delegate {
If (! Alreadynagged)
{
Alreadynagged = true;
New c1nagscreen (). showmodal ();
}
};
}));
}

This shows why nagproperty is set multiple times even if multiple controls are referenced, and the box is displayed only once when it is actually started.

If you want to set the alreadynagged field to true, use reflection. Unfortunately, the Silverlight security mechanism prevents us from setting private fields.

To continue, c1nagscreen inherits from c1window, while showmodal is the c1window method.

Public void showmodal ()
{
This. verifycanshow ();
If (this. _ canvas. Children. Contains (this) & (base. Visibility = visibility. Visible ))
{
Throw new invalidoperationexception ("showmodal can be called only on hidden windows .");
}
If (! This. _ canvas. Children. Contains (this ))
{
This. _ canvas. Children. Add (this );
}
Verifydefacancanvasinserted ();
This. _ context. modalwindow. Remove (this );
This. _ context. modalwindow. Add (this );
Base. tabnavigation = keyboardnavigationmode. cycle;
Base. Visibility = visibility. visible;
If (! Base. Focus ())
{
Base. Loaded + = delegate (Object S, routedeventargs e ){
Base. Focus ();
};
}
This. isactive = true;
This. fix#worder ();
This. bringpopuptofront ();
} Private void bringpopuptofront ()
{
Base. Dispatcher. begininvoke (delegate {
_ Contexts [_ defaultcanvas]. Popup. isopen = false;
_ Contexts [_ defaultcanvas]. Popup. isopen = true;
});
}

Carefully analyze and confirm that the pop-up window is a popup. Let's take a look at whether you can close the pop-up window. The following idea is implemented in mainpage:

Public mainpage ()
{
Initializecomponent ();

VaR timer = new dispatchertimer ();
Timer. interval = timespan. frommilliseconds (1 );
Timer. Tick + = new eventhandler (timer_tick );
Timer. Start ();
}

Void timer_tick (Object sender, eventargs E)
{
VaR pops = visualtreehelper. getopenpopups ();
If (Pops. Count ()> 0)
{
VaR Pop = pops. First ();
Pop. isopen = false;
(Dispatchertimer) sender). Stop ();
}
}

Success is a success, but it will be a flash. Further analysis, suspect that _ defacanvas canvas has a problem, and finally track the problem:

Public static void adddefaultpopuptovisualtree (Panel panel)
{
Initializedefacanvas canvas ();
Panel. Children. Add (_ defaultcanvas. Parent as uielement );
}

Private Static void initializedefacanvas canvas ()
{
If (_ defacanvas canvas = NULL)
{
_ Defacanvas canvas = new canvas ();
Context context = new context ();
_ Contexts [_ defacanvas canvas] = context;
_ Defacanvas canvas. setvalue (canvas. zindexproperty,-10000 );
Context. popup = new popup {Child = _ defacanvas canvas, isopen = true };
Attachapplicationroot ();
}
}


All eyes go to the static adddefaultpopuptovisualtree method. It is unclear whether this method is called inside the control, but if we call this method when the program starts. Pass in a visibility = "Collapsed" Panel. can I hide the pop window? Add a hidden grid to mainpage.

<Usercontrol X: class = "slc1window. mainpage">
<Grid X: Name = "layoutroot" background = "white">
<Grid X: Name = "poppanel" visibility = "Collapsed"/>
</GRID>
</Usercontrol>

The background code is as follows:

Public mainpage ()
{
Initializecomponent ();

C1window. adddefapopopuptovisualtree (poppanel );
}

It's easy, right? And I do want to work as expected. The window is no longer displayed.

However, there are also sequelae, which cannot be displayed after pop-up windows such as c1messagebox. Of course, you can also integrate method 1 and method 2 to reasonably solve this problem:

Public mainpage ()
{
Initializecomponent ();

C1window. adddefapopopuptovisualtree (poppanel );

VaR timer = new dispatchertimer ();
Timer. interval = timespan. frommilliseconds (1 );
Timer. Tick + = new eventhandler (timer_tick );
Timer. Start ();
}

Void timer_tick (Object sender, eventargs E)
{
VaR pops = visualtreehelper. getopenpopups ();
If (Pops. Count ()> 0)
{
VaR Pop = pops. First ();
VaR Panel = pop. Child as panel;
If (Panel = NULL | panel. Children. Count = 0)
Return;
VaR window = panel. Children [0] As c1window;
If (window = NULL)
Return;
Window. isactive = false;
Window. Visibility = visibility. collapsed;
Pop. isopen = false;
Poppanel. Visibility = visibility. visible;
(Dispatchertimer) sender). Stop ();
}
}

Of course, adjust it according to the actual project situation. Sample download link.

This is just a personal solution. I mainly want to talk about it. I hope it will help you with the same problem and look forward to communication.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.