首页 > 其他 > 详细

LevelHostControl.xaml

时间:2015-09-27 18:43:59      阅读:158      评论:0      收藏:0      [点我收藏+]
<local:LevelHostControl x:Name="levelHostControl" Height="580" Width="810" Canvas.Left="0" Canvas.Top="0" HostFile="Level1.xaml"/>

 

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="BeeHive.LevelHostControl"
    d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot">
        <ContentPresenter x:Name="PART_CONTENT"/>
    </Grid>
</UserControl>
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Resources;
using System.Windows.Shapes;

namespace BeeHive
{
    public partial class LevelHostControl : UserControl
    {
        public static readonly DependencyProperty HostFileProperty = 
DependencyProperty.Register("HostFile",
typeof(object),
typeof(LevelHostControl),
new PropertyMetadata(null, new PropertyChangedCallback(OnHostFileChanged))); public string HostFile { get { return (string)this.GetValue(HostFileProperty); } set { this.SetValue(HostFileProperty, value); } } private static void OnHostFileChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { LevelHostControl hostControl = (LevelHostControl)sender; string newValue = (string)e.NewValue; if (!string.IsNullOrEmpty(newValue)) { Uri uri = new Uri("/BeeHive;component/" + newValue, UriKind.Relative); StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri); StreamReader sr = new StreamReader(streamResourceInfo.Stream); object loadedLevel = XamlReader.Load(sr.ReadToEnd()); hostControl.PART_CONTENT.Content = loadedLevel; } } public LevelHostControl() { // 为初始化变量所必需 InitializeComponent(); } } }

 

LevelHostControl.xaml

原文:http://www.cnblogs.com/gaowen/p/4842488.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!