Create UserControl By using UltraGrid of Infragistics [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to create a custom control using Infragistics UltraGrid control. I want to add a button on top of the UltraGrid which exports data as excel. You can get better idea by viewing below image.
This grid is used many times in my project so that i need it in a user control. I have tried to create it but when i add this control in my project i cannot access all actual properties of that UltraGrid.
please help...

You are creating a composite control. Normally this means that you can't access the composing controls from the form where you want to position your usercontrol. Usually you need to provide the code to access the underlying properties and events of the controls that compose your UserControl.
For example, supposing that you want to change the caption of the UltraWinGrid inside your user control, you should write a get/set property like this in the code of the UserControl.
public string GridText
{
get
{
return ultraGrid1.Text;
}
set
{
ultraGrid1.Text = value;
}
}
As you can imagine, this is not a trivial task with a control like the Infragistics UltraWinGrid that has probably thousands of properties. Not to mention the long list of events.
See here a tutorial from Microsoft about building a Composite Control and that explain the problem with properties of the underlying controls.
A simple workaround (NOT RECOMMENDED) could be to change the property Modifiers of the UltraWinGrid and of the button from Private to Public. In this way the grid reference is available from the properties of the UserControl and you can program it as before.
userControl1.ultraGrid1.Text = "My User Control";
However this is not recommended because you give full access to the composing controls and this, in certain situations, could be not desiderable. It largely depends on your using scenario.

Related

Remove docking combo button from AvalonDock LayoutAnchorable [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm developing a vb.net WPF application (not using MVVM) that contains an AvalonDock LayoutAnchorable. What I want to know is, is there a way to remove the built-in Down-Arrow combo button that provides docking options from the LayoutAnchorable?
I do not think that there is an option to hide the drop-down button completely out-of-the-box. The anchorables do not seem to provide any properties or methods for hiding the button or customizing the header template easily.
However, you can remove the button for all anchorables by modifying the AnchorablePaneTitle style. You can find the default styles depening on your theme on GitHub in one of the Xceed.Wpf.AvalonDock.Themes.* directories. The styles are defined in Theme.xaml. You most likely use Aero, if you did not specify anything else.
Copy the style, e.g. Aero, to a resource dictionary in scope or the application resources. Then you can go to the drop-down button definition and set its Visibility to Collapsed. Do not delete this part, it is easier to simply hide it.
<xcad:DropDownButton x:Name="MenuDropDownButton"
Visibility="Collapsed"
... />
Keep in mind that this is not an easy edit, as it requires you to adapt the XML namespaces to the ones that you have imported in your XAML file and adapting the file paths to point to the right assembly, e.g.:
avalonDockProperties:Resources.Anchorable_BtnAutoHide_Hint would become xcad:Resources.Anchorable_BtnAutoHide_Hint for me, as I have added the corresponding namespce as xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
The file path Images/PinAutoHide_Dark.png is only valid in the source assembly, so it would become pack://application:,,,/Xceed.Wpf.AvalonDock.Themes.Aero;component/Images/PinClose_Dark.png
``
You could also reset the AnchorableContextMenu. It would prevent the context menu on the anchorables from showing up. If you did not modify the template, it would also prevent the drop-down button from showing any menu items, but the drop-down button would still be visible and clickable.
<xcad:DockingManager AnchorableContextMenu="{x:Null}">
Look at this image for a comparsion of the original and the modified template.

Why do we need UserControl ? It seams that a Custom Control can do all the things that UserControl can do. WPF & Windows Store App [duplicate]

I've been reading some explanations about the difference between User and Custom Controls, for example this:
http://www.wpftutorial.net/CustomVsUserControl.html
I want to create, for example, a simple composition of a datagrid with 2 comboboxes which are responsible to change the values from the datagrid's items. I want to create a specific control for this because I'm going to use it a lot of times. I would like to implement the logic behind and then in the xaml invocation I only have to specify the itemsSource.
For this example should I create a User or Custom control? Since I will have properties and logic, should I have a viewmodel for this control?
EDIT: Do you know some articles with clear conceptual separation between these 2 options?
Choice is not only between user control and custom control, but among user control, custom control, customizing control template, customizing data template, header template (for collection based controls), attached properties.
Refer to Control Authoring overview
I go by following order of consideration
Attached Properties : If functionality can be achieved, I use attached properties. Example, Numeric text box.
Control Template : When requirement can be fulfilled by customizing the control template, I use this. Example, circular progress bar.
Custom control: If control template cannot do it, I use custom control. Provided I need to customize/extend already present control. Example providing Sorting, Filtering based on header row in GridView (GridView is present in metro apps, used just to illustrate the example)
User control: Least preferred one. Only when composition is required, and I am unable to do it using custom control. Like in your example, 2 Combobox, and 1 datagrid. User controls does not provide seamless lookless feature that can be leveraged through custom control or control template.
You already have some great answers that explain the differences but also understand that custom controls and UserControls have different purposes:
A UserControl typically encapusulates some sort of composite behaviour. If you have an application that needs to edit contact details in many places, for example, you could create a custom control that has the labels and text fields for all the data laid out with a submit button that has the relevant code and reuse this control throughout your application.
A custom control is a control that is derived from one of the WPF control classes (E.G. Control, ContentControl etc.) and has to be created in code.
These control usually have a single cohesive purpose (think TextBox, ComboBox, Label) rather than acting together as a whole (although this doesn't have to be the case).
UserControl's are usually easier for people unfamiliar with WPF as they can be visually designed.
My suggestion would be to start off with a UserControl. You can always refactor this into a custom control at a later date as you become more familiar with the way WPF works. Creating your control as a custom control will require knowledge of ControlTemplates and Styles as you will need to provide your own to define a look and feel for your control.
When all is said and done, as long as the control behaves correctly, it doesn't matter which approach you use.
See this post for an example of two approaches to the same problem. The post author wanted a control which can present modal content in front of the primary content. The post author actually answered his own question by implementing it as a UserControl. I have added an answer to the post which creates the control as a custom control but both have the same end effect.
If you have a view-model and you wish to create a view for it use the User-Control.
If you need an autonomous control that has no specific view-model,
you probably need a custom-control.
If you find that the functionality you need as whole, already exist in other controls you need to override an existing control template.
(i.e: for a diamond shaped button - you need to override the button control template.)
Regarding attached-properties and attached-behaviors, those are useful when you have a control which you want to extend with more properties or you want it to behave slightly different than its default behavior.
In the provided case of the composition the OP described, it can be achieved with either user control or custom control. I would prefer a custom control since there is no specific view model provided, the "input" is only a property bound to an item collection.
Oh, and, I am sorry for slightly being late.
The best explanation is in the msdn. CustomControl is more a "virtual" name, there is no class called "CustomControl" in WPF, instead its meant creating a new class building on top of one of WPF control classes, like Control, ItemsControl and even more specific Controls like TextBox or Button.
For your specific case, a UserControl should be enough, creating a CustomControl is something that can easily be avoided. While its not a bad thing, a lot of people, especially beginners in WPF coming from WinForms tend to subclass more then necessary.
If this is somehow your first time building controls, I recommend UserControl as VS lets you design its interface more easily. Custom Controls are more powerful, but you have to CLEARLY separate your control's logic from its interface and this requires a bit more preparation.
You can easily Visually design CustomControl.
Create new UserControl (or Window). Create its xaml structure visually in Designer. Copy-paste body of the resulting xaml inside ControlTemplate of your new CustomControl (Eg. in generic theme file).
If I remember right, you are also able to visually design CustomControl template directly, in Blend.
Of course you can also instance the wip CustomControl in a Window and put the Window's Designer view as new panel above the control's xaml view in VisualStudio.
Some xaml bindings from style template don't show in Designer like this though, until I rebuild.
[ Imho GUI is mainly a visual matter and should not, and doesn't need to, be created in code. ]
Well to create a Custom control you need to implement it as a User control. Your own User control is called a Custom control. It is pretty simple.
UserControl is the base class for containing your custom content :
<UserControl>
Your custom WPF content
</UserControl>
I don't totally agree with the article. However in your case you need a UserControl that you can re-use latter in your UI.

How to get design time data in silverlight/wpf designer?

I want to have my user controls have design time data. If I add the data/datacontext using the constructor, I can see the data in the control from a different view that contains the control.
If I set the DataContext from xaml, I can see it when I'm designing the control, but I see nothing in a control that hosts the control.
So is there any example of how to get design time data to show up in a control if it is being edited, or it's parent is being edited? Or anything that lists the rules of then the constructor is run/not run from the designer? I'm trying to set a DesignViewModel with the data, and at runtime use the actual view model.
If I understand your question correctly then it's answered in this question

.NET (C#) winforms "tweet" UI control question [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm a real dummy at UI building, so I'm wondering - what .NET winforms control would be best to use if aiming to display tweets in a list fashion that updates with like boxes which contain the text of the tweet and its metadata below it. Is there a specific winforms list function for this type of thing? Or do you recommend I look for/use a third party winforms control? Thanks! Hope my question wasn't too silly.
UPDATE: I am getting indication from numerous responses that it would be better to just build a simple winform control myself, but can anyone point me to a tutorial for doing so? Also, if i were to build such a control, does there exist a convenient built-in control for making like a list of custom controls that is scrollable - maybe Panel? Thanks in advance!
I'd build a user control that would display the information for a single tweet. I'd then repeat that user control in a panel.
You could just use the same layout in your user control that is standard for "tweets".
Left justified picture box to display the user image.
LinkLabel for user name.
Label for tweet text.
Update: Here are a couple pages on UserControls
http://msdn.microsoft.com/en-us/library/a6h7e207(VS.71).aspx
http://www.akadia.com/services/dotnet_user_controls.html
Create a usercontrol using the designer and also a Tweet class that is
just a dumb data structure to hold each tweet's information. Also create a Tweet
property on the custom user control that would handle setting the tweet and assigning information
to the standard controls contained in it (Labels, Textboxs, PictureBox, etc).
In the form where you want to host your user control create a panel that is empty. Somewhere in your code you
would do something similar to this code block.
pnlHost.Controls.Clear();
List<Tweet> tweets = new List<Tweet>();
//Populate your collection of tweets here
foreach (Tweet tweet in tweets)
{
TweetControl control = new TweetControl();
control.Tweet = tweet;
pnlHost.Controls.Add(control);
control.Dock = DockStyle.Top;
}
Hi I'd go for a third party grid control from companies like Infragistics, DevExpress or Telerik. Another option would be to build a usercontrol that is able to display one post and put that control into a vb.net repeater control (which ships with the vb.net powerpack). However I'm not sure how good the last solution actually works, as I just read about it, but never tried it.
Try using DataGridView (and a DataTable behind it) and overwrite the CellPainting event to draw the tweets the way you like it.
Edit
I think using a custom control is a bit heavy just to display the tweets. Basically this depends on the desired functionality of the displayed tweets - what would you like to do with them. For example, if you just want the user to click the tweet and then redirect him to some webpage in the browser then the DataGridView will do just fine since you can attach this action to the CellClick event. Plus you already have the sorting/searching capabilities of the DataTable (and the related DefaultView)behind it. Hell, you can even attach a ContextMenuStrip to the tweet and have unlimited options with the RightClick.
On the other hand if you need some functionality that is not available in the DataGridView (for example, you would like 5 different buttons at the bottom of the tweet and 3 checkboxes on the right) then the custom control would do you better because you could build practically everything you wanted. In this case OG explains this nicely.
Try listbox, it's easy to use and seems like it will suit your needs.

public datagridview within user control is "locked" during design time when subclassing

I have a user control that has among other things a label AND a textbox control. With this class, I set the textbox to have its modifier as "public", so when I subclass THIS control, I can get directly to the properties and such of the textbox in each instance where needed. No problem.
Now, the problem. I do the exact same thing but with a dataGridView control (and some others) within a user control. Set ITs modifier to public with intent to derive this user control downstream. Now, I try to derive this control to a NEW control and can't directly touch the dataGridView and add columns, sizing, etc directly.
I tried reproducing the described behavior and was able to do so with the GUI designer in VS 2008 using .Net 3.5. I suspect you are running into the same issue as this problem
That means to get the desired behavior you may need to implement a custom designer. There is even an example designer given by another person answering the question. Please have a look and see if that helps.

Categories