Is there a way to make a "click-to-edit" control in silverlight? I've got some items that
will be displayed in a treeview control, and I would like the labels to be editable directly in the treeview.
Anyone know how to do this?
Very easy actually. I have implemented many forms with such a swapping mechanism.
You could do this using a Converter and do a simple BooleanToVisibility conversion on an IsEditable property that exists on the entities that you bind to your TreeView. Within your TreeView ItemTemplate just bind the TextBlock in such a way that it is Collapsed whenever the IsEditable property is true and bind the TextBox in such a way that it is collapesed when IsEditable property is false (and vice versa).
If you wanted to build a custom ClickToEdit control you would need to do the following:
Create a class that inherits from ContentControl
Expose a new dependency properties of type DataTemplate: one called EditableTemplate.
Add a MouseLeftButtonUp event handler inside your OnApplyTemplate to listen for the click.
Change the active content template to be your EditableTemplate on the click event.
Change the template back when the control loses focus.
Now to use your custom control inside TreeView:
Override your ItemTemplate for your TreeView
Put your custom ClickToEdit control inside there
Implementing a custom control would allow you (or other developers) to easily specify what control they wanted to use as the content editor. For example, they could specify a NumericUpDown or a DateTimePicker instead of just using a TextBox.
Check out DataForm in Silverlight 3. It has similar functionality but the switching of the editable vs. read-only is not done by a click.
Related
I am making a template using Usercontrol in WPF(C#).
However, when applying this user control, is it possible to subtract a specific part? For example, removing a button?
To substract specific parts from UserControl, Visibility (Collapse, Hidden) option can be used.
Make sure to add dependency property in UserControl for Visibility to show & hide specific part.
It sounds like you are just trying to hide an existing button, which you should do by setting Visibility to Visibility.Collapsed or Visibility.Hidden. This should be done through a binding to the ViewModel of your user control.
If you need a pure XAML solution: No it is not possible as such. However, the reverse is possible: you can add content to a user control, and that effectively provides the same functionality.
What you could do is make a base user control that doesn't contain the button, and instead has a content presenter. A second user control could wrap the base user control and define a button as its content. Then when you don't want to use the user control with the button you can simply create an instance of the base user control.
I am aiming at creating different UserControls for my college project, in which I am attempting to use ContentControl to wrap my UserControl. I've placed other Controls like Image, WebBrowser, MediaElement and the like, now I have reached a stage where I need to set the properties for my UserControls. Thus, I thought of making use of PropertyGrid Control, but now the problem I am facing is in the PropertyGrid control, as I get all the default properties of the Controls, which in my case I don't want.
For Eg: if I use Image Control then i need properties like Source and Stretch to be displayed only in the PropertyGrid. Can anyone help me in achieving this?
I tried to override some default properties like "Name" and assign it as [Browsable(false)] to hide it from being displayed. I don't want to do this for all the other properties which are being displayed and which are not under my requirements as well.
I am using Xceed.Wpf.Toolkit for my PropertyGrid.
It is explained in the documentation on how to do that:
http://wpftoolkit.codeplex.com/wikipage?title=PropertyGrid
When you change the selected object see SelectedObjectType and set PropertyDefinitions in code to match the properties you want to see for that type of object.
I've written a custom WPF menu control (similar to a tab control, I suppose) using a ListView to hold the headers, which then can be clicked to switch to the appropriate page. The problem with this is, when I'm coding up the XAML for windows that use the control I can't see anything past the first page in the designer view.
Is there a way to let me switch the view within the Visual Studio designer?
If your ViewModel has something like a SelectedTab property that is bound to your custom menu control's SelectedItem dependency property, then you could change your design-time data (or your design-time ViewModel) to make that tab selected by changing the SelectedTab property appropriately.
Is there a control that allows to choose data, that should be in it? For example: red one - static page, blue is dynamic, below are buttons that allow to switch pages in dynamic part.
I use the dockpanel suite for this:
dockpanel suite
This contol is designed to mimic the vs.net tabs.
Try using a ContentControl databound to a property on your UserControl. Change the property when you want to update the content. Ensure that the property is either and DependencyProperty or that your user control implements INotifyPropertyChanged.
http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx
This is achived by using DataTemplates. You just bind the SelectedItem of the "red" control (e.g. a ListView) to the Content of the "blue" Control (it should be a ContentPresenter).
You add DataTemplates to the Resources accessable by the "blue" control which will then display different content depending on the underlaying class/data.
How to create custom checkbox that looks like the one shown below. The checkboxes are dynamically drawn and can have custom colors.
Well, you can just style it. Take the style from here and change it. The key component in the style is VisualStateManager, make sure you understand what it does.
Also you can create a custom control, you can read about it, for example, here.
What I would do is, create a custom control called ImageCheckBox which inherits from the default CheckBox class, add in three dependency properties of type ImageSource, called CheckedImage, IndeterminateImage and UncheckedImage. Just toggle their Visibility or Opacity based on the control's CheckStates, i.e. Checked, Unchecked and Indeterminate.