Open a Popup from a Scrollviewer - c#

I'm making a WinRT application using XAML and I have a control that has a TextBox and a Popup that opens under it when the TextBox get focus.
The Width of the Popup is the same as the Width of the TextBox. This works fine but if I put my control in a ScrollViewer and zoom in the size of the popup doesn't change. I would like to achieve something similar to the standard ComboBox which changes the size of its Popup when it is nested in a ScrollViewer. What should I do?
I know that the popup must be part of the VisualTree but I'm not quite sure how to add it without changing the existing layout.
Thank you

To have the popup be parented in the TextBox you can either modify the template of the TextBox and put it in there (you could subclass TextBox to both add support for your dropdown logic and change the default template at the same time) or simply find the root Grid of the TextBox using VisualTreeHelper. By default TextBox has a Grid at its root, so you could get that and add the Popup to its Children.

Related

WinForms UserControl can't Focus properly

I have a WinForms UserControl that accepts keyboard input, and had a Scrollbar for scrolling, and everything was fine. Recently I swapped the Scrollbar control out for a custom scrollbar (also a UserControl), and now after clicking the custom scrollbar, my custom control loses focus and the only way to get it back is to click a different focusable control (like a TextBox) and then click back in my UserControl. If the scrollbar has focus and I click inside my UserControl to give it focus, I notice the LostFocus event is raised and the scrollbar keeps the focus
I tried setting the UserControl's Selectable control style to true, it didn't help.
Any idea why it would behave this way?
I figured it out. I used
SetStyle(ControlStyles.ContainerControl, false);
In the UserControl's constructor. Because it had the ContainerControl flag set by default, it would preferentially give the focus to a child control.

How to create an user control containing collapsed text that is expandable on button click?

Is it possible to create a WPF user control like this - a text region which is shown couple of lines initially and when user clicks a button it will open up the rest of the text ?
I have checked the expander class but dint find any properties with this behavior.
The nearest example I can think of of such a behavior is the ToggleButton.
You can modify its default Template to show whatever you want.
The default Template: http://msdn.microsoft.com/fr-fr/library/cc296245%28v=vs.95%29.aspx

How design left menu panel

in windows wpf i want design a left bar menu like this:
when i click on an item, in the right the window change.
With which control can i design this?
Tab bar control?
Or a left dock panel and insert inside it some button? In this case how can I change the window on the right when click on a button?
If each time you click on a button you want to display a different view, you could define each of your views in a separate control and in your main window within a grid declare each view in a DockPanel.
Then by binding the visibility property of each DockPanel you can create the logic in order to display only what you want on each click.
I suggest using a styled ListBox and binding the Visibility property of your content to it. Even better you can also use a styled Tab control.

Using a DatePicker without TextBox (Silverlight Toolkit) WP7

I am developing an app for Windows Phone 7.8 (probably WP8 at a later date) that needs the user to enter a date. I am currently using the DatePicker control from the Silverlight Toolkit as I like the visual style of it.
The DatePicker control, when placed on the page, is shown as a TextBox that when clicked opens the DatePicker.
Is there anyway to not have the TextBox included as I do not need and it is cluttering up my form. Maybe a way to open the DatePicker through code rather than trough the OnClick event?
Any help is appreciated :)
You can simply edit the Control Template of the DatePicker to change the way it looks.
VS 2012 can do this by default (right click and edit template), else you will need to edit the template using Expression Blend.
In particular, the Control Template consists of a Button (among other things):
<Button x:Name="DateTimeButton"
Content="{TemplateBinding ValueString}"
...
The Buttons Content property is bound to ValueString. If you remove this Binding (for example) you will be left with a blank button. You could put anything you like in the content of the button...
These links should help you get started with using Blend:
Styling a control that supports templates
Create or modify a template
The guides on Project Rosetta are nice too.
may be, you can create the DatePicker and hiden it.
when you click item (item which you want to use), you change focus to DatePicker.
I think that you can instantiate the DatePickerPage object and navigate to it. As I understand it has a Value property (coming from the IDateTimePickerPage interface) which you can set and read.
I cannot test it at today but I will definitely try it tomorrow and let you know what I found. Meantime you can go to the http://silverlight.codeplex.com/ page and check the source of the Toolkit.
What is the event that should trigger the opening of the datepicker page? Is it a click or tap on a button, an image or what?
If it is any of these, you could place a DatePicker in xaml over that control so that they overlap (placing them in a grid's same row, same column). Set the Opacity of the DatePicker to 0. Then the user will not see the DatePicker's TextBox, just the control below it. However, when the user clicks on that control (button, image, etc), he or she will in fact click on the invisible DatePicker and then the datepicker page will open up.

Show UserControls In "ItemsControl" with custom option in XAML

I have a ItemsControl in ScrollViewer and I set ItemsPanel of my ItemsControl to Horizontal StackPanel and i bound it to ObservableCollection of userControls.Now I wanna when user click on icons of open UserControls in my ItemsControl,automatically scrollviwer's offset change to show icon clicked UserControl.( I have a Icon for my each usercontrols)
And also when user open new UserControl ,I wanna my ItemsControl automatically show it ( now when I open a new usercontrol i should scroll my ItemControl to reach it),
can I do this with above controls ,if yes, can you tell me how? If not, I appreciate to tell me which controls should I use controls and how?

Categories