Monday, February 9, 2009

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection

<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://www.blabla.com/"/>
    </baseAddressPrefixFilters>
</serviceHostingEnvironment>

You encounter this error in the web.config file and enter the above code in the part.

Wednesday, February 4, 2009

Silverlight and Cookie

DateTime expiration = DateTime.Now.AddDays(5);
string cookie = string.Format("ad={0};expires={1}", txtCookie.Text, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);

Read All Cookies in Silverlight

var cooks = HtmlPage.Document.Cookies.Split(';');
foreach (var s in cooks)
{
    cook = s.Split('=');
    MessageBox.Show(cook[1]);
}

This also can easily access cookies by asp.net.

SilverLight And Double Click


Normally, double-click does not exist in Silverlight.But within a period of time after you press the left button pressing the left button  double click event in a more duration 300 ms.


public partial class Page : UserControl
    {
        DispatcherTimer timer;
        public Page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Page_Loaded);
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(300);
            timer.Tick += new EventHandler(timer_Tick);
        }

        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (timer.IsEnabled)
            {
                MessageBox.Show("Double Clicked.");
            }
            else
            {
                timer.Start();
            }
        }
    }

Sunday, February 1, 2009

Sql Server Read An External Scheme and Create

declare @schema xml
select @schema=c from openrowset(bulk 'c:\data.xsd',single_blob) as temp(c)
create xml schema collection DataSchema as @schema

Tuesday, January 20, 2009

Call A Javascript Function With Silverlight

ScriptObject script = (ScriptObject)HtmlPage.Window.GetProperty("ChangeImg");
script.InvokeSelf();

İlk satırda sayfasımızda yer alan ChangeImg adlı fonksiyona erişiyoz ve alt satırda bu fonksiyonu çalıştırıyoruz.

Eğer parametre göndermek istersek;
script.InvokeSelf("par1","par2");

Monday, January 19, 2009

Read A Xml Document With Silverlight(XLINQ)

private void btnSend_Click(object sender, RoutedEventArgs e)
{
string uri = Application.Current.Host.Source.AbsoluteUri;
int index = uri.IndexOf("/ClientBin");
uri = uri.Substring(0, index);
txtAd.Text = uri;
WebClient client = new WebClient();
client.DownloadStringAsync(new Uri(uri+"/data.xml"));
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}

okuma tamamlandığında ise;
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
XElement element = XElement.Parse(e.Result);
txtAd.Text = (from x in element.Descendants("musteri")
select x.Element("ad").Value).First();
}
catch (Exception ex)
{
System.Windows.Browser.HtmlPage.Window.Alert(ex.InnerException.Message);
}
}

Silverlight Send Parameter And Start Random Page

string sayfaAdı=e.InitParams["ad"]
var myPage=(UserControl)this.GetType().Assembly.CreateInstance(this.GetType().Namespace + "." + ad);
this.RootVisual = myPage;

veya daha kolay olarak girilen parametreye sayfayı belirleriz.
switch (ad)
{
case "Page1":
this.RootVisual = new Page1();
break;
case "Page2":
this.RootVisual = new Page2();
break;
default:
this.RootVisual = new Page();
}