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.
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'm using an ItemsControl to generate a list of controls based on my model.
When looking at the visual tree, i noticed that each of the rendered control is wrapped in a ContentPresenter. The controls that are added are a 3rd party control and are designed to display a splitter between each control if they are siblings..this allows a user to size each control. For example the following will show a splitter between each of the controls at run time.
<StackPanel>
<3rdPartyControl />
<3rdPartyControl />
<3rdPartyControl />
</StackPanel>
When using an ItemsControl, each of the 3rdPartyControl are wrapped in a ContentPresenter, and thus no splitter is shown. I have tried various ways to try and solve this problem but unable to get this to work unless i write code behind to add each control rather than rely on Xaml.
Does anyone know of a way to replace the contentpresenter completely (in my case with 3rdpartyControl)?
Thanks
In order to replace the ContentPresenter you could derive from ItemsControl and override the GetContainerForItemOverride method to create a specialized container control.
ListBox for example overrides this method to create a ListBoxItem as container for a new item object.
That's true, every element that you add to ItemsControl is wrapped with ContentPresenter, you can find more details about it in the greate series of articles from dr.wpf ItemsControl a-z
One way I would suggest to try is to change ItemsControl to ListBox and make ListBox act like ItemsControl. In this case you can re-style/re-template ListBoxItem and replace ContentPresenter with your control. You would also need to stop selection support. Here is ListBox style that you need to change.
I'm fairly new to WPF and I have this scenario:
I have an application that contains an area where different sets of controls should be displayed at different time(different application states).
I'm wondering what is the approach in WPF?
In winforms I would make controls visible/invisible at runtime. If there were too many controls I would group them on Panels/UserControls and show/hide those.
My gut tells me there is a better way in WPF.
There are lots of options for doing this in WPF. In addition to hiding and showing individual or groups of controls by setting Visibility, you could use different DataTemplates to contain the set of controls for each state and switch between those. All you need is a ContentControl on which you can set the ContentTemplate. The ContentTemplate value can then be switched to different DataTemplates using a Trigger, a Binding, from code, or by using ContentTemplateSelector to choose a template.
The Visibility property describes your old winforms habits perfectly.
You'll also want to look into Visual States. This will allow you to hide/show multiple controls and even change other properties (i.e. enable state, font color).
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.