RSS

Category Archives: Silverlight

change tooltips from codebehind silverlight


You can set or change Tooltips from the code behind file.How can i write a code for ToolTip in Code Behind ,so follow this…

ToolTipService.SetToolTip(ButtonName, "This is new tooltip");

find control from codebehind from silverlight:
var button = e.Row.ChildrenOfType<HyperlinkButton>().Where
(b => b.Name == "lbtnStarted").FirstOrDefault();

 //front side
 <telerik:GridViewColumn Width=".2*">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton x:Name="lbtnStarted" Content="" 
CommandParameter="{Binding Pkcampaignid}" 
Click="lbtnStarted_click" ToolTipService.ToolTip="Change Status">
</HyperlinkButton>
</DataTemplate>
  </telerik:GridViewColumn.CellTemplate>
 </telerik:GridViewColumn>

//Codebehind

 private void grdcampaign_RowLoaded(object sender,
 Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.DataElement != null)
            {
                if (e.Row.DataContext != null)
                {
  var button = e.Row.ChildrenOfType<HyperlinkButton>().Where
(b => b.Name == "lbtnStarted").FirstOrDefault();
                    tblcampaign tblst = e.Row.DataContext as tblcampaign;

                    if (Convert.ToString(tblst.Status) == "Running")
                    {
                        button.Content = "Stopped";

ToolTipService.SetToolTip(button, "Change Status to Started");
                    }
                    else if (Convert.ToString(tblst.Status) == "Stopped")
                    {
        ToolTipService.SetToolTip(button, "Change Status to Stopped");
                        button.Content = "Started";
                    }
                    else if (Convert.ToString(tblst.Status) == "Pause")
                    {
      ToolTipService.SetToolTip(button, "Change Status to Started");
                        button.Content = "Started";
                    }

                }
            }
        }
Advertisements
 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , , , ,

upload csv file in silverlight


upload csv file in silverlight with header.

read csv file and write into database with class…….

//Create List with class

List<tbltest> lArrObjclsGridLoadExcelData = new List<tbltest>();

//Read CSV File and write in class
public void lFnLoadCSVDataInGrid()
{
try
{

lArrObjclsGridLoadExcelData.Clear();
int j = 1;

OpenFileDialog dlgOpen = new OpenFileDialog();
dlgOpen.Filter = “CSV Files (*.csv)|*.csv”;
bool? res = dlgOpen.ShowDialog();

if (res == true)
{

txtCSV.MaskedText = dlgOpen.File.Name;
txtCSV.IsReadOnly = true;

StreamReader lObjStreamReader = new StreamReader(dlgOpen.File.OpenRead());

bool lBlnIsColumnRow = true;

while (lObjStreamReader.Read() != null)
{
string lStrLine = lObjStreamReader.ReadLine();

if (lBlnIsColumnRow)
{
lBlnIsColumnRow = false;
continue;
}

if (lStrLine == null)
break;

if (lStrLine.Trim() == “”)
continue;

string[] lArrStrCells = null;

lArrStrCells = lStrLine.Split(“,”.ToCharArray());

if (lArrStrCells == null)
continue;

if (!(lArrStrCells.Length == 11))
continue;

tbltest lObjclsGridLoadExcelData = new tbltest();

lObjclsGridLoadExcelData.Leadidpk = j;
lObjclsGridLoadExcelData.Listidfk = j;

lObjclsGridLoadExcelData.Phonecode = Convert.ToSByte(lArrStrCells[0]);
lObjclsGridLoadExcelData.Phonenumber = lArrStrCells[1];
lObjclsGridLoadExcelData.Title = lArrStrCells[2];
lObjclsGridLoadExcelData.Firstname = lArrStrCells[3];
lObjclsGridLoadExcelData.Lastname = lArrStrCells[4];
lObjclsGridLoadExcelData.Surename = lArrStrCells[5];
lObjclsGridLoadExcelData.Address1 = lArrStrCells[6];
lObjclsGridLoadExcelData.Address2 = lArrStrCells[7];
lObjclsGridLoadExcelData.City = lArrStrCells[8];
lObjclsGridLoadExcelData.State = lArrStrCells[9];
lObjclsGridLoadExcelData.Zip = lArrStrCells[10];
lObjclsGridLoadExcelData.Datetimecallback = DateTime.Now;
lObjclsGridLoadExcelData.Comments = “”;
lObjclsGridLoadExcelData.Agent = “sajjad”;
lObjclsGridLoadExcelData.Attempts = 2;

lArrObjclsGridLoadExcelData.Add(lObjclsGridLoadExcelData);

j++;
}

lObjStreamReader.Close();
lObjStreamReader.Dispose();

}
//  return lArrObjclsGridLoadExcelData;
}
catch (Exception ex)
{
//  lFnShowPopupErr(ex.Message.ToString());
// return null;
}
}

 

 

load csv in datagrid

 

private void btnUpload_Click(object sender, RoutedEventArgs e)
{

try
{
lFnLoadCSVDataInGrid();
       grdList.ItemsSource = lArrObjclsGridLoadExcelData.ToList();
}

catch (Exception)
{
throw;

}

}

 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , ,

Download CSV File in Silverlight


Hi…

you can download csv,excel or image file like jpg ,jpeg,bmp or any formate file from server on local system then

you just use this code and resolve your problem.

This line below find out the actual path of application

 string str = App.Current.Host.Source.AbsoluteUri;

// you can replace and get the path of specific folder and file with in it.

str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

 

 

 

 

 

 

 

 

 

private void sampleupload_Click(object sender, RoutedEventArgs e)
{

SaveAs();

}

public void SaveAs()
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = “csv Files|*.csv”;

bool? dialogResult = dialog.ShowDialog();

if (dialogResult != true) return;

WebClient webClient = new WebClient();
webClient.OpenReadCompleted += (s, e) =>
{
try
{
using (Stream fs = (Stream)dialog.OpenFile())
{
e.Result.CopyTo(fs);
fs.Flush();
fs.Close();
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
};
string str = App.Current.Host.Source.AbsoluteUri;
str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

webClient.OpenReadAsync(new Uri(str), UriKind.Absolute);
}

 

 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , , , , , , , ,

Invalid cross-thread access in silverlight


Now when I receive DataServicesQuery.EndExecute and use this to pupulate a list that is bound to a usercontrol via a view model I get: “System.UnauthorizedAccessException: Invalid cross-thread access”

this error also heppend in silverlight application when you create user control or after fill list<myobj> and pass to griddate or radgridview( Telerick) control.

but here is suggests the following fix:

 

Dispatcher.BeginInvoke(
() =>{
CustomersGrid.ItemsSource = nwContext.EndExecute<Customers>(asResult).ToList();
}
);

 

Also use like………

 

You can change the code above so that the query executes on the UI thread by using the Deployment.Current.Dispatcher object.
e.g.:

Deployment.Current.Dispatcher.BeginInvoke(

() =>{
ICustomerModelInstance.GetCustomers();
}
);

 

 

 

 
Leave a comment

Posted by on February 24, 2012 in Silverlight

 

Tags: , , , , , , ,

How to set control Height Width Auto in silverlight


You need to use your code like this:

MyComponent.Width = double.NaN;

suppose you have a rectangle as your object named rect

rect.SetValue(Rectangle.HeightProperty, Double.NaN);

suppose you have a grid as your object named mygrid

mygrid.SetValue(Grid.HeightProperty, Double.NaN);

 

your place this where you reset height or Initialize or page_load event like

  public  CallerInfo()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}

 

void Page_Loaded(object sender, RoutedEventArgs e)
{
myGrid.SetValue(Grid.HeightProperty, Double.NaN);
rect.SetValue(Rectangle.HeightProperty, Double.NaN);

}

 

Warning!

rec.SetValue(Rectangle.HeightProperty,”Auto”); not worked

its giving me error “DependencyProperty of type System.Double cannot be set on an object of type System.String”.

 
1 Comment

Posted by on February 15, 2012 in Silverlight

 

Tags: ,

how to disable Silverlight ScrollBar Visibility


Hi dear.

if you want to disable scrollbar from codebehind then use this code ……..

<ScrollViewer VerticalScrollBarVisibility=”Auto” HorizontalScrollBarVisibility=”Auto” IsHitTestVisible=”True” x:Name=”sviewer”>

///Write Grid Control here

</ScrollViewer>

sviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
sviewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;

 

 
Leave a comment

Posted by on February 15, 2012 in Silverlight

 

Tags: , , , ,

Find control inside silverlight


There is no other way to finding a control inside a Silverlight page or controls. You need to traverse the container (Grid) element. this is a generic function that can find any type of control in side a container(Grid) control using recursion.

public T FindControl(UIElement parent, Type targetType, string ControlName) where T : FrameworkElement
{

if (parent == null) return null;

if (parent.GetType() == targetType && ((T)parent).Name == ControlName)
{
return (T)parent;
}
T result = null;
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);

if (FindControl(child, targetType, ControlName) != null)
{
result = FindControl(child, targetType, ControlName);
break;
}
}
return result;
}

 

 

parent: is the container control that needs to be traversed for the desired control like grid.
targetType: Target Control type.
ControlName: is the name/Id of the control to be searched for.

 

how to call this function like here
TextBlock ControlToSearch = FindControl<TextBlock>((UIElement)ContainerControl, typeof(TextBlock), “NameOfTheControl”);

or

for (int k = 1; k <= TotalCountCbo; k++) {

RadComboBox ControlToSearch = FindControl<RadComboBox>((UIElement)myGrid, typeof(RadComboBox), “cboname” + k);

}

Method will return the desired control if found in container otherwise NULL.

 
Leave a comment

Posted by on February 6, 2012 in Silverlight

 

Tags: , , , , , ,