集成ascx.cs文件? VS2010 [英] Integrating ascx.cs file? VS2010

查看:66
本文介绍了集成ascx.cs文件? VS2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的银灯应用程序中的解决方案项目文件夹中有以下代码。它的天气应用程序代码。如何让它在Silverlight或WPF应用程序中运行?你能给我举例说明如何用它来绑定文本框

使用System; 
使用System.Collections;
使用System.Configuration;
使用System.Data;
使用System.Web;使用System.Web.Security
;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml;

使用Dropthings.Widget.Framework;
使用Dropthings.Widget.Widgets;

公共部分类Widgets_WeatherWidget:System.Web.UI.UserControl,IWidget
{
#region Fields

private IWidgetHost _Host;
private string weatherLocation =" http://xml.weather.yahoo.com/forecastrss?p =" ;;
private string zipCode =" 22202" ;;

#endregion字段

#region属性

public IWidgetHost Host
{
get {return _Host; }
set {_Host = value; }
}

#endregion属性

#region方法

公共字符串GetWeatherData()
{
string url = weatherLocation + zipCode;

XmlDocument doc =缓存[url]为XmlDocument ?? (new XmlDocument());
try
{
if(!doc.HasChildNodes)doc.Load(url);
}
catch
{
return string.Empty;
}
if(null == Cache [url])Cache [url] = doc;

XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes(" / rss / channel / item");
string data ="" ;;
foreach(节点中的XmlNode节点)
{
data = data + node [" title"]。InnerText;
data = data + node [" description"]。InnerText;
}
返回数据;
}

void IEventListener.AcceptEvent(object sender,EventArgs e)
{
throw new NotImplementedException();
}

void IWidget.Closed()
{
}

void IWidget.Collasped()
{
}

void IWidget.Expanded()
{
}

void IWidget.HideSettings()
{
pnlSettings.Visible = false;
}

void IWidget.Init(IWidgetHost host)
{
this.Host = host;
}

void IWidget.Maximized()
{
}

void IWidget.Restored()
{
}

void IWidget.ShowSettings()
{
pnlSettings.Visible = true;
}

protected void LoadContentView(object sender,EventArgs e)
{
this.Multiview.ActiveViewIndex = 1;
this.MultiviewTimer.Enabled = false;

if(!Page.IsPostBack)
{
if(this.Host.GetState()。Trim()。Length == 0)
{
//lblWeather.Text = GetWeatherData();
}
else
{
//lblWeather.Text = this.Host.GetState();
zipCode = this.Host.GetState();
}
}
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

lblWeather.Text = GetWeatherData();
}

protected void Page_Load(object sender,EventArgs e)
{
if(Page.IsPostBack)this.LoadContentView(sender,e);
}

protected void btnSave_Click(object sender,EventArgs e)
{
zipCode = txtZipCode.Text;
lblWeather.Text = GetWeatherData();
this.Host.SaveState(zipCode);
(这是IWidget).HideSettings();
}

#endregion方法
}



解决方案

您好lzMnelson,


您可以考虑将其发布在以下更合适的论坛上,以获得更有效的回复。谢谢!


silverlight: http://forums.silverlight.net/


WPF: http://social.msdn.microsoft.com/forums/烯/ WPF /线程/


I have the following code in my Solution items folder in my silver light application. Its code for a weather app. How do I get it to work in silverlight or WPF application? Can you give me example of how I would use this to bind to a textbox

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

using Dropthings.Widget.Framework;
using Dropthings.Widget.Widgets;

public partial class Widgets_WeatherWidget : System.Web.UI.UserControl, IWidget
{
    #region Fields

    private IWidgetHost _Host;
    private string weatherLocation = "http://xml.weather.yahoo.com/forecastrss?p=";
    private string zipCode = "22202";

    #endregion Fields

    #region Properties

    public IWidgetHost Host
    {
        get { return _Host; }
        set { _Host = value; }
    }

    #endregion Properties

    #region Methods

    public string GetWeatherData()
    {
        string url = weatherLocation + zipCode;

        XmlDocument doc = Cache[url] as XmlDocument ?? (new XmlDocument());
        try
        {
            if (!doc.HasChildNodes) doc.Load(url);
        }
        catch
        {
            return string.Empty;
        }
        if (null == Cache[url]) Cache[url] = doc;

        XmlElement root = doc.DocumentElement;
        XmlNodeList nodes = root.SelectNodes("/rss/channel/item");
        string data = "";
        foreach (XmlNode node in nodes)
        {
            data  = data + node["title"].InnerText;
            data  = data + node["description"].InnerText;
        }
        return data;
    }

    void IEventListener.AcceptEvent(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void IWidget.Closed()
    {
    }

    void IWidget.Collasped()
    {
    }

    void IWidget.Expanded()
    {
    }

    void IWidget.HideSettings()
    {
        pnlSettings.Visible = false;
    }

    void IWidget.Init(IWidgetHost host)
    {
        this.Host = host;
    }

    void IWidget.Maximized()
    {
    }

    void IWidget.Restored()
    {
    }

    void IWidget.ShowSettings()
    {
        pnlSettings.Visible = true;
    }

    protected void LoadContentView(object sender, EventArgs e)
    {
        this.Multiview.ActiveViewIndex = 1;
        this.MultiviewTimer.Enabled = false;

        if (!Page.IsPostBack)
        {
            if (this.Host.GetState().Trim().Length == 0)
            {
                //lblWeather.Text = GetWeatherData();
            }
            else
            {
                //lblWeather.Text = this.Host.GetState();
                zipCode = this.Host.GetState();
            }
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        lblWeather.Text = GetWeatherData();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack) this.LoadContentView(sender, e);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        zipCode = txtZipCode.Text;
        lblWeather.Text = GetWeatherData();
        this.Host.SaveState(zipCode);
        (this as IWidget).HideSettings();
    }

    #endregion Methods
}


解决方案

Hi lzMnelson,

You can consider posting it at the following more appropriate forum for more efficient responses. Thanks!

silverlight: http://forums.silverlight.net/

WPF: http://social.msdn.microsoft.com/forums/en/wpf/threads/


这篇关于集成ascx.cs文件? VS2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆