How to hide and show silverlight user control on main Silverlight Control? - c#

I have a main silverlight control named MainPage.xaml in an asp.net web site.
I want to dynamically add and remove control at run time.
So,
I have created another control Top10.xaml and added to selected canvas area on MainPage.xaml as described on this page(Click Me):
Now i need to modify Top10 visibility in MainPage.xaml dynamically when a button is clicked on MainPage.xaml using C# code in MainPage.xaml.cs.
Can anybody help me out?
Thanks

for programmability you might wanna set an id for the control u declare in xaml.
you could say x:Name="top10" or something similar.
on the click event of the button you could use the code below
top10.Visibility = Visibility.Collapsed; // to hide
top10.Visibility = Visibility.Visible; // to show
Hope this helps.

Related

How to force a focus on a control in windows forms

I am trying to focus a "search" textbox control in my windows forms application. This textbox is inside a user control, which is inside a panel which is inside a windows form (if it is important).
I tried 3 methods which I could find:
// 1
this.ActiveControl = myTextBox;
// 2
myTextBox.Focus();
// 3
myTextBox.Select();
Neither of them seems to work. I mean for example when I try the first one, active control is really set to myTextBox, but when I try to write something on keyboard, textbox doesn't accept it and I have to first click inside the textbox to get focus. This is same with all of the methods.
Am I missing something?
Ok, finally found the answer:
As I said my textbox is inside user control which is inside panel which is inside a form.
When I need my user control I add it to panel. To get focus on my textbox I have to firstly focus my user control so something like this:
In my top Form:
panel.Controls.Add(myUserControl);
myUserControl.Focus();
and then in my user control:
myTextBox.Select();
Note that if I used: myTextBox.Focus() it wouldn't work (don't know why). Also if I used myUserControl.Select() instead of myUserControl.Focus() it wouldn't work either.
This seems to be the only combination which works.
You could do these logic steps to set your control to be the focus:
your_control.Select();
your_control.Focus();
Enjoy! :)

Can I add already created pages to tab control?

I have a tab control with tabs on it in a windows application. I have already created some pages. Can I make these pages display on tabs of the tab control?
Thanks in advance.
Make Usercontrols of your pages and add them as TabPages
edit:
To add forms to a TabControl, you will first want to set a Panel inside of a page in the TabControl. Then, do the following in the constructor of the form with the TabControl:
FormToLoad formToLoad = new FormToLoad();
formToLoad.TopLevel = false;
panelInTabPage.Controls.Add(formToLoad);
formToLoad.Show();
You may also want to individually style your forms so that they don't show window chrome.

How do you navigate to a new page in a metro app?

trying to write a metro app in C# right now. Ran into a problem while trying to navigate to a new page.
<HyperLinkButton NavigateUri="foo.xaml"/>
doesn't work, as the NavigateUri field doesn't exist.
The Windows.Navigate namespace isn't available either, so no luck there. What's the proper way to go to a new page in my app in metro?
You can handle the Button control's Click event (in fact, you can use all events with the following code) because Metro's HyperLink button only inherits the ButtonBase class without any special properties or events, such as NavigateUri.
If you want to navigate to another page in your metro app, add a frame in the .xaml page and put this code in the button's event handler:
this.Frame.Navigate("VideoStoryCreator.ComposePage");
There are two ways of Navigating to another page -
Client app way ->
You'll implement this in click event -
var page = new PageName();
Window.Current.Content = page;
Similar to Silverlight Navigation
If you are using Frame/Page Navigation then you can do it like this -
Create a shell page (master page) with the element declared. Then instead of creating new pages with create .
The easiest way to do this is to replace UserControl with Page
This is nicely explained in this tutorial -
http://www.markermetro.com/2011/11/technical/windows-8-metro-style-apps-implementing-navigation-with-xaml/
Hope it helps!
Regards,
Bhavik
Handle the Click event on the button and then call the Navigate method on your Frame
just type the following code in your click event
this->Frame->Navigate(TargetPageName::typeid,this);

How to launch DatePickerPage from ApplicationBarIconButton?

I've tried to launch DatePickerPage after ApplicationBarIconButton is tapped.
I had hope that it would be easy as follows:
DatePickerPage dpp = new DatePickerPage();
dpp.Show();
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = dpp.Value.ToString();
...but it wouldn't.
Could you give me some suggestions, please?
I don't think the DatePickerPage is really intended to be used directly. The key control here is the DatePicker, which itself handles showing the picker page. For detailed information about using the DatePicker control, check out this article on WindowsPhoneGeek.com.
Given that the label of appbar icon buttons is not visible by default, it seems a bit strange to update the label in this way. What are you trying to achieve?
Maku, I'm letting users activate a datepicker from the ApplicationBar by placing it in the page and setting Height/Width to zero and then focusing the DatePicker when the ApplicationBarIcon is pressed.

Display another layout on button click

I have a layout MainPage.xaml in which i have images and a button.
On click of button i want another layout Top.xaml to be displayed such that MainPage.xaml becomes invisible.
I am new to Windows phone 7?
Can someone help out?
This depends on what you are looking to do. You can either navigate from MainPage.xaml to Top.xaml using
NavigationService.Navigate(new Uri("Top.xaml", UriKind.Relative));
If you just want to switch between layouts (i.e. not navigate to a whole new page) you can implement both layouts in one XAML page and switch between them using VisualStateManager. Create one state called "Main" and other called "Top" then switch from one to the other as follows:
VisualStateManager.GoToState(this, "Top", true);
It all depends on how you want to layout your code and also how you expect the back button to work. Using states means you will have to handle the back button yourself.

Categories

Resources