Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - WPF - Databinding Color to plain simple Window or Canvas in a Window Background - No controls -


i need answer can explore. running brick wall here:

i use:

        (int c = 0; c < 255; c++)         {              color = color.fromargb(255, (byte)c, (byte)(255 - c), (byte)c);             thread.sleep(3);         } 

each time "color" recomputed, window or canvas in window change color...so see cool color changes. why hard? need see this, i'm hitting brick wall. copied type converter here:

[valueconversion(typeof(color),typeof(solidcolorbrush))] public class colorbrushconverter : ivalueconverter {       public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         color color = (color)value;         return new solidcolorbrush(color);     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         return null;     }  } 

thank help!

a simple example of how can bind color property code behind canvas background. things note

  • implement inotifypropertychanged. background canvas updated upon onpropertychanged execute everytime mycolorproperty changes.
  • setting datacontext = this; in constructor make controls in window inherit datacontext (unless overriden).

xaml

<canvas ...>     <canvas.background>         <solidcolorbrush color="{binding mycolorproperty}"/>     </canvas.background> 

code behind

public partial class mainwindow : window, inotifypropertychanged {     public mainwindow()     {         initializecomponent();         this.datacontext = this;     }      // ...      private color m_mycolorproperty;     public color mycolorproperty     {                 {             return m_mycolorproperty;         }         set         {             m_mycolorproperty = value;             onpropertychanged("mycolorproperty");         }     }     public event propertychangedeventhandler propertychanged;     private void onpropertychanged(string propertyname)     {         if (propertychanged != null)         {             propertychanged(this, new propertychangedeventargs(propertyname));         }     }      private void switchbackground()     {         if (mycolorproperty == colors.red)         {             mycolorproperty = colors.black;         }         else         {             mycolorproperty = colors.red;         }     } } 

update
run background animation can use backgroundworker this

private backgroundworker m_changecolorbgworker = null;  public mainwindow() {     initializecomponent();     this.datacontext = this;     m_changecolorbgworker = new backgroundworker();     m_changecolorbgworker.dowork += new doworkeventhandler(m_changecolorbgworker_dowork); } private void button1_click(object sender, routedeventargs e) {     if (m_changecolorbgworker.isbusy == false)     {         m_changecolorbgworker.runworkerasync();     } } void m_changecolorbgworker_dowork(object sender, doworkeventargs e) {     while (true)     {         (int c = 0; c < 254; c++)         {             mycolorproperty = color.fromargb(255, (byte)c, (byte)(255 - c), (byte)c);             thread.sleep(10);          }     } } 

you can set mycolorproperty directly in thread because changes fired inotifypropertychanged automatically marshalled onto dispatcher. not go inotifycollectionchanged however, know.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -