I am silverlight beginner and i am in a situation that i have to pop up a message box containing three buttons (Yes/No/Ok). Please do not give me the following suggestion(I already tried and tired) :
(1) Use Childwindow : Though it is a good solution but the way it pop ups is not like MessageBox pop up because in message box pop up we can see clearly
the data behind but we cannot edit/click/change it whereas in child window pop up it is less visible. (So if you know any way to make childwindow back ground
visible just like MessageBox then you are most welcome to tell me alternatives).
(2) Use PopUp control : Because it do not pop up exactly and can be distuinguished easily from MessageBox and the data behind is always editable when PopUp control is pop-Uped and if i set it to Collapsed then it show nothing. So i want pop up exactly like MessageBox.Show() Pop Ups.
Whereas in MeassageBox.Show() we can see that when it is pop uped the GUi behind is visible but not clickable and the way it Pop ups is perfect so i want
something that could Pop up exactly the same way with three buttons on it.
Could some one please help me in achieving my target ?
If I understand the question, you want a popup in the default MessageBox style, only with Yes/No/OK buttons. Recognize that there is not an ideal solution -- even the Windows API (which you don't have access to in Silverlight outside of full trust) doesn't provide this combination of buttons (without using advanced techniques anyway).
So, you are left with the non-ideal options of making use of Popup or ChildWindow. I think it would be misguided to try and mimic the exact style of the Windows dialog popup, since that style depends on the system, which you don't have access to from Silverlight. Instead, I recommend just choosing a style that you are comfortable with, and which matches the theme of your application.
In any case, as with all controls, you have two options for styling ChildWindow:
1) Modify its style properties like OverlayOpacity, BorderBrush, etc. Take a look at the default control template to see how those properties are used in the control's presentation.
2) If you need to do more customization than the default template allows, then you can always copy-and-modify the ControlTemplate. That allows you fine-grained control over everything about the popup's appearance, including its open/close animations. There's lots of info on the web about modifying control templates (eg, MSDN).
Related
I am not using anything other than a simple WPF application project in visual studio. I've implemented an mvvm application.
I want to display a list of content changes made by a user. I have a main window view model and it currently just builds a strings with changes. I have objects that I can reuse to display their properties (the content).
Currently, I use a MessageBoxResult to show a really long string with the changes. This is a terrible design (I know), but I couldn't really find an answer to what class a regular wpf project has that would allow me to achieve what I want.
I know there is a popup class I can use. In practice, which is better-- another view model for the dialog, or a popup?
Can anyone provide a simple example of one of the two approaches?
Thank you in advance for your response.
What I've done in the past is have a simple Border control, and inside of a TextBlock and whatever Button controls I need. I bind the TextBlock.Text to a public string property named "MessageBoxMessage" which calls OnPropertyChanged(). I bind the Command of each Button to a separate public ICommand which specifies what action to take in the view model when the button is clicked. I then bind the visibility of the Border control - which contains all of the other controls I mentioned - to a Visibility property.
When I want to show a dialog, I set the MessageBoxMessage to the message I want to show, makes sure the commands are set properly, and then set the Visibility on the Border to Visibility.Visible. This shows the box (border), message, and buttons.
You can even implement a semi-transparent rectangle underneath the border (over the rest of the form) that you set to visible at the same time. This will give you the nice "form dimmed" effect and also block the normal form controls from being clicked. A general note - for this to work, these controls need to be at the very bottom of your XAML as the z-index among controls at the same level is inferred from their placement in the XAML - lower in the code is top level on the form.
Let me know if you have any questions about implementing this if it sounds like what you are looking for.
I'd like to control which button is focused in my view. User must be able to perform a job without need to use mouse. And job is going through all elements. Depending on element, some buttons will appears, some disappears.
I could do it with dependency properties. To example, if there are buttons Previous and Next, then I can provide IsPreviousFocused and IsNextFocused to set focus to them after certain event. Events can be: showing window for the first time (something should have focus already), reaching 1 element (hiding Previous button, setting IsNextFocused), reaching last element (opposite), etc.
This looks reasonable more or less.
But, if I have, to example, 10 buttons (different operations), then all of them will have to have dependency property!
So I was thinking about much easier approach: when I hide button, there will be no focus
if(FocusManager.FocusedElement == null) { ... }
If I can detect, when there are no focus, then I can try to set it to one of the buttons somehow. This way, I don't really need any complicated focus management
Question is: how to deal with FocusManager.FocusedElement in MVVM scenario? How to detect when there is no focus (when window is shown first time, when certain button is clicked and become invisible, etc)?
P.S.: I actually hate ms for making another technology without thinking fully into it; focus is very basic feature (and everybody care about it in their software), but there is no direct support for it (in xaml); looks like "oh, its too complicated, lets skip it" solution.
You could control your focus from your ViewModel by using the approach shown here:
Set focus on textbox in WPF from view model (C#)
In LightSwitch, when I open the default modal, calling the AddAndEditNew_Execute method, I want to change properties of the controls inside the modal dialog.
For instance: I want to change a TextBox to "Multiline" or change AutoComplete FilterMode to "Contains".
How can I access to those controls in execution time?
I know I can add a custom modal, but I just want to change a small thing of it and I don't want to create a whole modal dialog just for this.
I'm always talking about Silverlight client.
Thanks in advance.
I'm afraid that the only way you can do what you want is:
with a custom modal window (if you want the window to be modal)
or a separate screen (if you don't need the window to be modal)
The properties of a default modal window can't be changed. There are no mechanisms to change the properties of any of the controls.
The only thing that you can do is to influence which properties get displayed in the default modal window, by checking/unchecking the Display By Default check-box in the table designer.
But as soon as you need to make changes to either the layout of the controls, or changing any control's properties, you need to create a custom modal window, or separate screen, & display then by calling them in custom code.
The reason for this is because the controls for the default modal window are generated by the LightSwitch run-time.
It's really just a matter of a balance between not having to do the work to create the window, & flexibility.
Default: Easy = Yes, Flexible = No
Custom: Easy = No, Flexible = Yes
I know it's not what you wanted to hear, but hopefully my explanation helps you to understand why you can't do it the way you first wanted to.
I'm developing a WPF application in C# and was thinking about implementing a custom UI element accross various windows.
I would like to have a minimized tray (only about 4px visible) that expands after clicking on an icon next to the tray. The expanded version would show all controls and would minimize when I click the icon again. I created a quick HTML concept to clarify things.
I know I could put a stackpanel and button in my application and making both of them move up when I click the button, but then I would need to duplicate the code a lot.
Though I'm experienced with C#, I'm fairly new to WPF interface development/templates, but I'm sure there has to be a way so I can use that UI element accross my application without needing to copy/paste a lot of lines of code in my form class file.
I hope someone can help me, or at least point me in the right direction.
There are three ways to customize your elements.
1 If you only need visual modifications you can use styles to change the appearance of the .net default controls. You can even override / extend the default templates.
2 If you want custom logic in a control you can create a custom control. The framework brings a lot of "primitives" to build upon. Examples are ContentControl or HeaderedContentControl. Say you want to build a custom expander control you can inherit your custom control from HeaderedContentControl which provides you with Header and Content properties and you just have to implement the toggling logic yourself.
CustomControls are a good choice if you want to build basic functionality which can be used throughout your application. They can be themed/styled depending on the use case, too (see 1).
3 If you want to compose different controls into one control you can create a UserControl. User controls are composed using XAML. Most top level controls are user controls driven by a view model.
Your case can be build using a Popup and ToggleButton or an Expander.
The decision depends on the desired behavior. If you want the opened panel to move following content down you need a expander. If you want a dropdown like functionality you need popup.
If you use a popup just bind the IsPopupOpen Property to IsChecked of the ToggleButton and set PopupStaysOpen = false to wire the button to your popup.
If you use an expander control you should create a style which can be applied to all equal expanders in your application to minimize the required XAML in each view.
How about using Expander Control?
There's a control called an Expander that is perfect for this. You'll have to style it to look like you want, however it has the functionality you want built-in.
I am adding layout management to my winforms GUI which really just means that you can "Save" the current column settings with a "Key"
so for example you can have "View 1" or "View 2".
anyway, i dont have much real estate on the screen but i am trying to figure out the best way to:
Allow you to save the current layout as a "Saved Layout"
Allow you to select another layout and apply it.
Right now i have:
Save Icon
Combobox that has a list of saved layouts
Apply Icon
It works ok but it look a little unclear because the dropdown combobox is available and doesn't necessarly correspond to the view you are looking at.
I thought one idea was to instead of showing the combo, to just have two buttons:
Save layout
Apply existing layout.
when you clicked #2, this would then turn into a dropdown and show the other layouts.
thoughts or any other suggestions on a clear way to visualize this?
When space is tight, I'm a big fan of the LinkLabel and the ContextMenuStrip controls.
Save would pop up another form or something for entering the name of the current layout (or this could be set automatically), and Load displays the saved layouts in a popup menu that can then be clicked to select the desired layout.
LinkLabels take up less room than Buttons and ComboBoxes, and there's never any confusion about how they work.
I like your second idea, with one button to save and one generating a dropdown + apply
from my experience it's sometimes better to separate such logic into own modal window to select what to do and near your layout would be an icon suggesting for "advanced usage"
always try to "comment around" the components (use hints as much as possible) to tell the user what can be done with specific functionality
alt text http://www.talkingtext.com/wordpress_en/wp-content/uploads/2008/04/googleproduct.jpg
I try to keep the UI as uncluttered as I can, particularly when it comes to functionality that is of a more ancillary nature. To that end, if I can utilize something like a context menu that the user can right-click to pull up, I will. From the context menu, I generally provide a dialog box to support the functionality needed.
If the saving of the layout is a primary function of the form you are displaying to the user, it might warrant UI elements like a button or combo box that has dedicated real estate. Otherwise, I'd think seriously about putting the controls that provide that functionality on another pop-up dialog and using a mechanism like a context menu to bring up that dialog.
The downside to the context menu idea, initially, is that the user needs to "know" that the functionality exists. That might be solved by training or by tooltip hints or other means. Typically once the user "knows" that controls like ListViews, TreeViews and DataGridViews can have context menus, they don't have problems finding the functionality.
Just my two cents.