Put the XAML on the server, that is, change to the current .....

Source: Internet
Author: User

After a long time, I slept .....

First play with the above Silverlight stuff

First, we can see the above interface and put the following code

  

<UserControlxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"Width="640" Height="480"><Grid x:Name="LayoutRoot" Background="White"><ed:BlockArrow Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="50" Margin="112,48,0,0" Orientation="Right" Stroke="Black" UseLayoutRounding="False" VerticalAlignment="Top" Width="100"/><ed:Callout AnchorPoint="0,1.25" CalloutStyle="Oval" Content="Callout" Fill="#FFF4F4F5" FontSize="14.666999816894531" Height="100" Margin="248,48,192,0" Stroke="Black" VerticalAlignment="Top"/><ed:RegularPolygon Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" InnerRadius="0.47211" Margin="64,0,0,116" PointCount="5" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" VerticalAlignment="Bottom" Width="100"/></Grid></UserControl>

  Copy it to the text box above, and click "display interface button" ...... Haha, that's right, the interface is displayed.

.........

But what's more interesting is that if you give a piece of XAML that meets the three conditions, copy the XAML to the text box and click the display interface button to display the interface.

1: The XAML format is good. The root is Page or UserControl.

2: NO x: Class...

3: note that your XAML does not reference a third-party class library.

... Yes, you can modify the XAML at will, and click the button to display the interface.

 

 

The source code is as follows... because the code is too simple, it will not be integrated into the package.

Below is the code for clicking a button.

private void button1_Click(object sender, RoutedEventArgs e)        {            string xaml = textBox1.Text;            try            {                UserControl uc = System.Windows.Markup.XamlReader.Load(xaml) as UserControl;                ChildWindow c = new ChildWindow();                c.Content = uc;                c.Show();            }            catch (Exception ee)            {                MessageBox.Show(ee.Message);            }        }

Haha... the code is so simple ......

My goal is to change the current status.

In our actual development, even if our XAML only makes a very small change, we have to go through the compilation phase to see the effect. XAML must be repackaged near XAP. As the project grows, compilation and packaging will take longer and longer. When the project is relatively large, even if we make a very small function change, we must re-generate a new XAP package.

The immediate change means that after the change, you can immediately see the effect without compiling.

For example, in the small example above, several lines of code implement a simple version of "instant change". Make any qualified changes to the XAML, and click the button to display the results.

Of course, the above content cannot be used for projects. In actual project development, our Xaml certainly cannot be edited in that small text box. It is best to use Blend for editing. (There are some friends who think that learning Silverlight does not require Blend. This is definitely a false idea .)

Therefore, if you can use Blend to edit the XAML and click a button to see the modification effect within 0.5 seconds, it must be nice.

 

On the code

That's right. As I mentioned above, use Blend to edit the code, and click here to view the Code as follows.

Http://files.cnblogs.com/MySilverlight/demo2.xap

Code Description:

1: After you open the code, find the directory ...... \ demo2 \ SilverlightApplication2.web \ ClientBin \ MyXaml \ XamlShow. You will find a solution in this directory. Open it with Blend.

2: After opening the file, find the three ready-to-use XAML files. Open UserControl1.xaml first

 

3: Open SilverlightApplication2.sln and use. Then, browse the Default. aspx page. Or simply press F5 and you will see the following interface

 

Click the show interface button, and you will see the UserControl1 XAML loaded interface. Is it exactly the same as that in Blend ??

That's right.

You can change UserControl1 to UserControl2 or UserControl3. all these three files are ready for use. Note: press Ctrl + s to save the edited Blend.

Remarks

Is it much easier to treat our XAML in this way ?? Of course, if this method can only be changed to XAML for us and can only be used for game play, then I have no value for this article .... in actual development, The XAML is put on the server like this .....

You will ask, how is the resource Dictionary (Style File) half when the XAML is put on the server? How can I load images? The image can be displayed in the Blend. Can this mechanism be used to display images ?? What should I do if I want to reference a third-party DLL ?? The path here has only one Test folder. If the Test folder contains multiple directories, how can this problem be solved ???

But I know, the biggest problem here is what to do with the... CS file? You need to know a XAML, which corresponds to a CS file in our previous development. Even if MVVM is used, the page must have the corresponding CS code ......

Well, that's right. I have solved all these problems .....

Predict the future and listen to the next decomposition.

 

 

 

 

 

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.