I have made and rss reader and have a listbox with all the feeds in it. When I select one item and want to see the whole article I only get the selectedindex number, 0,1,2 and so on.
Here is my code:
private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
NavigationService.Navigate(new Uri("/DetailsPage.xaml?feeditem=" + listBox.SelectedIndex, UriKind.Relative));
}
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string feeditem = "";
if (NavigationContext.QueryString.TryGetValue("feeditem", out feeditem))
{
this.textBlock1.Text = feeditem;
}
}
What am I missing here?
Related
I' have some navigation page and I want to override the color for the back button and my next button ( ToolbarItem )
I Already tried BarTextColor property but it change color for all navigation header text.
It's done in IOS, but I' not able to find a solution for android.
It works perfectly for the title but not for the Icons.
Here my code :
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var page = this.Element as NavigationPage;
if (page != null && toolbar != null)
{
toolbar.SetTitleTextColor(Color.Black.ToAndroid());
if (toolbar.NavigationIcon != null)
toolbar.NavigationIcon.SetColorFilter(Color.Green.ToAndroid(), Android.Graphics.PorterDuff.Mode.Multiply);
if (toolbar.OverflowIcon != null)
toolbar.OverflowIcon.SetColorFilter(Color.Green.ToAndroid(), Android.Graphics.PorterDuff.Mode.Multiply);
}
}
I' have some navigation page and I want to override the color for the back button and my next button ( ToolbarItem )
Your next button is a ToolbarItem, which is defined by yourself. So it won't be a problem for you to customize it. The difficult part lies in the back button, because it is offered by Xamarin.Forms. You need to override the NavigationPageRenderer to change the color:
public class MyNavigationPageRenderer : NavigationPageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var navController = (INavigationPageController)e.NewElement;
navController.PushRequested += NavController_PushRequested;
navController.PopRequested += NavController_PopRequested;
}
}
private void NavController_PopRequested(object sender, Xamarin.Forms.Internals.NavigationRequestedEventArgs e)
{
Device.StartTimer(TimeSpan.FromMilliseconds(220), () =>
{
ChangeIconColor();
return false;
});
}
private void NavController_PushRequested(object sender, Xamarin.Forms.Internals.NavigationRequestedEventArgs e)
{
ChangeIconColor();
}
private void ChangeIconColor()
{
int count = this.ViewGroup.ChildCount;
var toolbar = GetToolbar();
if (toolbar.NavigationIcon != null)
{
var drawable = (toolbar.NavigationIcon as DrawerArrowDrawable);
drawable.Color = Resource.Color.material_grey_850;//set the navigation icon color here
}
}
private AToolbar GetToolbar()
{
for (int i = 0; i < this.ViewGroup.ChildCount; i++)
{
var child = this.ViewGroup.GetChildAt(i);
if (child is AToolbar)
{
return (AToolbar)child;
}
}
return null;
}
}
A little explanation to the codes above: PushRequest and PopRequest fires when you push and pop a new page to the navigation page and it is the perfect time for you to customize the existing Toolbar's NavigationIcon. So first find the Toolbar using GetToolbar then change the icon color by ChangeIconColor.
I want to access values of the insert form in Telerik radgrid. how can i do that this is what i am trying
protected void RadGrid3_InsertCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string a = (editedItem.FindControl("ID") as TextBox).Text;
string b = (editedItem.FindControl("Quantity") as TextBox).Text;
}
}
It throws me the following error
Object reference not set to an instance of an object.
When editing or inserting a grid item, you could access and modify the controls generated in the editable item (reference Telerik documentation).
Try something like this:
protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
string a= editableItem["Id"].Controls[0] as TextBox;
string b= editableItem["Quantity"].Controls[0] as TextBox;
}
}
Please note that I have not tested the the above snippet. For more references you can look here
I am developing a small game type application,when user wins the game he will get the popup as win for this I wrote the below code.
public void stoptimer()
{
if ((Convert.ToString(b1.Content) == "1") && (Convert.ToString(b2.Content) == "2") && (Convert.ToString(b3.Content) == "3") && (Convert.ToString(b4.Content) == "4") && (Convert.ToString(b5.Content) == "5") && (Convert.ToString(b6.Content) == "6") && (Convert.ToString(b7.Content) == "7") && (Convert.ToString(b8.Content) == "8") && (Convert.ToString(b9.Content) == "9") && (Convert.ToString(b10.Content) == "10") && (Convert.ToString(b11.Content) == "11") && (Convert.ToString(b12.Content) == "12") && (Convert.ToString(b13.Content) == "13") && (Convert.ToString(b14.Content) == "14") )
{
newTimer.Stop();
time = txtClock.Text;
//textBox2.Text = txtClock.Text;
Popup buyNowScreen;
buyNowScreen = new Popup();
buyNowScreen.Child =
new popupscreen
();
buyNowScreen.IsOpen = true;
buyNowScreen.VerticalOffset = 100;
buyNowScreen.HorizontalOffset = 25;
}
}
And I wrote the below code for navigate from popup page to other pages but it is not working getting the NullReferenceException.
private void button3_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/NumericEasy.xaml", UriKind.Relative));
}
private void ClosePopup()
{
Popup buyPop = this.Parent as Popup;
if (buyPop.IsOpen)
{
buyPop.IsOpen = false;
}
}
Here is the procedure for giving events to popup page's controls.
Popup buyNowScreen=new Popup();
popupscreen popup1=new popscreen();
buyNowScreen.Child =popup1;
buyNowScreen.isOpen=true;
popup1.button1.click+= new RoutedEventHandler(btn_playagain_click);
private void btn_playagain_click(object sender, EventArgs e)
{
p.IsOpen = false;
NavigationService.Navigate(new Uri("/NumericEasy.xaml?Refresh=true", UriKind.Relative));
}
Navigation service works between pages, you cant use a popup so simple. This service can't find, what page to use, that's why it's throwing an exception.
To solve your problem, you should do this:
Popup class
1)At your popup constructor you should get PhoneApplicationPage object.
private PhoneApplicationPage _page;
public SomePopup(PhoneApplicationPage page)
{
_page = page;
2) You should create a new type for click event.
public delegate void NavigateHandler(object sender, EventArgs e, PhoneApplicationPage page);
public event NavigateHandler NavigateFromPopup;
3) At your button_click event you should call it:
public void ButtonX_Click(object sender, RoutedEventArgs e)
{
if (NavigateFromPopup!= null)
NavigateFromPopup(this, EventArgs.Empty, _page);
}
Your page class
4) At your page, when you create a popup, you should add this eventHandler:
SomePopup p = new SomePopup(this);
p.NavigateFromPopup +=new SomePopup.NavigateHandler(p_NavigateFromPopup);
5) And finally, at your page you should write down this event:
private void p_NavigateFromPopup(object sender, EventArgs e, PhoneApplicationPage page)
{
page.NavigationService.Navigate(new Uri("...", UriKind.RelativeOrAbsolute));
}
That should work.
Basically i am trying to pull the contacts from the phone and showing them in the Listpicker control for a feature in my app. I have two Listpickers, one for name of contacts list and the other showing the list of phonenumbers for the chosen contact.
Here is my code:
//Declarations
ContactsSearchEventArgs e1;
String SelectedName;
String SelectedNumber;
List<string> contacts = new List<string>();
List<string> phnum = new List<string>();
public AddressBook() // Constructor
{
InitializeComponent();
Contacts contacts = new Contacts();
contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
contacts.SearchAsync(string.Empty,FilterKind.None,null);
}
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
e1 = e;
foreach (var result in e.Results)
{
if (result.PhoneNumbers.Count() != 0)
{
contacts.Add(result.DisplayName.ToString());
}
}
Namelist.ItemsSource = contacts;
}
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum.Clear();
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
private void Numbers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedNumber = (sender as ListPicker).SelectedItem.ToString();
}
Am able to populate the Numberlist with phonenumbers for the chosen name at the Listpicker background, but the number is not showing up in the front. I think Numbers_SelectionChanged() event is called only one time when the page loads and am not seeing it triggerd when i change the contact list. Anyone has an idea of where am going wrong ?
If you change
List<string>
To
ObservableCollection<string>
this should work.
Also then you only need to set the ItemSource once, in Xaml or you constructor.
But you may run into another issue with the November 2011 Toolkit and ListPicker.
See more in thread.
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum = new List<string>(); // Changed instead of phnum.Clear()
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
This works !!. While debugging i found its phnum.Clear() giving a problem. So i thought to create a new instance of phnum list for selected contact.
I have to format (backcolor, forecolor, font style) a radgrid's cells depending on the value of the cell.
For example
If the value is negative set the fore color of that cell as red.
Can any one please tell me how this can be achieved?
protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
{
TableCell cell = item["Column"];
cell.BackColor = Color.PeachPuff;
}
}
}
Add the line onItemDataBound="Data_OnitemDataBound" to your radGrid declaration in your aspx page.
Then add this to your code behind. The number in the Cells[] is the index of the column you want to modify or validate against.
protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToDecimal(item.Cells[3].Text) < 0)
{
item.Cells[3].ForeColor = System.Drawing.Color.Red;
}
}
}
Below code can be used for all the cells in the RadGrid.
protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
foreach (GridDataItem dataItem in RadGridProduct.MasterTableView.Items)
{
int cellCount = dataItem.Cells.Count;
foreach (GridTableCell item in dataItem.Cells)
{
if (item.Text == null ||Convert.ToInt32(item.Text) < 0 )
item.BackColor = System.Drawing.Color.Brown;
}
}
}